murali
murali

Reputation: 227

Google Maps API drawing Polygon with collection of Markers

I have a collection of Markers in an array which were pushed when user clicked on map, and need to place polygon over map using these markers. it works fine if markers are in proper order, which means when user clicked them in any particular direction.

polygon when user clicked markers in correct order

But if he user clicked on map randomly, markers would be random and the polygon looks as follows. enter image description here

How can I sort these markers so that how ever the user clicked on map, I get a polygon as depicted in first image??

Upvotes: 2

Views: 2938

Answers (1)

npinti
npinti

Reputation: 52185

You will need to find the Convex Hull of the points. You should find some help on this Google Page (You will need to view the source of the page).

Upvotes: 4

Related Questions