简体   繁体   English

Google Maps API绘制带有标记集合的多边形

[英]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. 如果标记顺序正确,则效果很好,这表示用户在任何特定方向上单击它们时。

用户按正确顺序单击标记时的多边形

But if he user clicked on map randomly, markers would be random and the polygon looks as follows. 但是,如果用户随机单击地图,则标记将是随机的,并且多边形如下所示。 在此处输入图片说明

How can I sort these markers so that how ever the user clicked on map, I get a polygon as depicted in first image?? 我该如何对这些标记进行排序,以使用户在地图上单击后都能得到第一个图像中所示的多边形?

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). 您应该在 Google Page上找到一些帮助(您需要查看页面的源代码)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM