问题
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