views:

10

answers:

1

I have a collection of GPS coordinates (Lat/log) in an array that I want to use to create a polygon in google maps. If i use the unsorted array, the polygon lines are drawn in the order of the array index.

I am wondering if there is a way to sort the array such that when i draw the polygon, the borders do not overlap. Any insight will be appreciated. Thanks!!

A: 

Find a central point for the collection of points, even one that isn't in the set but is an average or median of the points.

Then sort the array by increasing (or decreasing) order of vector angles from the central point to each point.

wallyk
This approach would only work for a subset of polygons, right? With some concave polygons it would fail, if I am not wrong. But I guess that is impossible to know from just a set of points of course, so your answer holds.
Peter Jaric