Check whether or not a point is in a polygon (Google Maps API)
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.
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
Yes it is possible. See this function: http://github.com/tparkin/Google-Maps-Point-in-Polygon
精彩评论