How to detect if a marker is inside a polygon in google maps

拜拜、爱过 提交于 2020-07-14 08:28:29

问题


I've got loads of coordinates for a polygon in a database. I also have coordinates for an marker in my database. How do i detect if the marker is inside this polyon.

Note: I use a cronjob to move the marker, and in this cronjob it needs to detect this. So javascript isn't involved!

Shape of polygon is not just a circle or square. It could be for example a country or sea.


回答1:


There is now a function in the Google Map API that does that.

Google Map coordinates in polygon

containsLocation(point:LatLng, polygon:Polygon);    
isLocationOnEdge(point:LatLng, poly:Polygon|Polyline, tolerance?:number);



回答2:


you should SELECT your polygons and SORT them in two different forms one by the x-axis, one by the y-axis, each time GROUPing them by the same parameter. then make sure the y coordinate of you marker point is between the y-coordinates of the polygon points of the same x. and that the marker y is between the x of the polygon points with the same y.




回答3:


If you use mysql spatial extensions, you can use link text function



来源:https://stackoverflow.com/questions/3069627/how-to-detect-if-a-marker-is-inside-a-polygon-in-google-maps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!