Is there a way to loop through a multipolygon feature using google maps v3 to extract each sub polygon and then use containsLocation() to find out if a location within the sub polygons matches my stored Lat and Long coordinates?
I'm expecting to be able to use a loop like so:
//check if multipolygon
if(e.feature.getGeometry().getType()==='MultiPolygon'){
//loop over sub polygons
var polygons = e.feature.getGeometry().getArray();
polygons.foreach(function(item, index){
//item is our polygon?
var coords = item.getAt(index).getArray();
var poly = new google.maps.Polygon({
paths: coords,
});
//check if the subpolygon contains my latlong
if(google.maps.geometry.poly.containsLocation(myLatLong, poly)){
// do something
}
});
}
However, it doesn't work as I don't think 'item' is actually a polygon?
Any help would be great on how I can achieve this.
google.maps.Polygons
from the coordinates, then do the check, so the posted code should in principle work. Please provide a minimal reproducible example that demonstrates your issue. – geocodezip