How to detect that a point is inside a Polygon using Google Maps?

Natim picture Natim · Jun 14, 2010 · Viewed 32.2k times · Source

I would like to detect that a google.maps.LatLng is inside a google.maps.Polygon.

How can I do that ?

Cheers,

Answer

swapnil udare picture swapnil udare · Sep 15, 2012

You can use this in google map V3:-

google.maps.geometry.poly.containsLocation(google.maps.LatLng(latitude, longitude),polygons);

polygons is a object returned by function after polygoncomplete.

var polygons=null;
google.maps.event.addDomListener(drawingManager, "polygoncomplete", function(polygon) {
        polygons=polygon;
});

reference by https://developers.google.com/maps/documentation/javascript/reference