问题
So I have a map here
How can I, using Google Maps API, detect whether or not a given coordinate is within that polygon? Is that possible?
Thanks in advance.
回答1:
Yes it is possible. See this function: http://github.com/tparkin/Google-Maps-Point-in-Polygon
回答2:
Google provides one already
var bermudaTriangle = new google.maps.Polygon({
paths: [
new google.maps.LatLng(25.774, -80.190),
new google.maps.LatLng(18.466, -66.118),
new google.maps.LatLng(32.321, -64.757)
]
});
google.maps.event.addListener(map, 'click', function(event) {
console.log(google.maps.geometry.poly.containsLocation(event.latLng, bermudaTriangle));
});
https://developers.google.com/maps/documentation/javascript/geometry#containsLocation
来源:https://stackoverflow.com/questions/3943634/check-whether-or-not-a-point-is-in-a-polygon-google-maps-api