Iam trying to find the polygon in which the given cordinate resides.
Here is the code for parsing the kml file :
for (var i = 0; i < doc[0].placemarks.length; i++)
{
for(var j= 0; j<doc[0].placemarks[i].Polygon[0].outerBoundaryIs[0].coordinates.length; j++)
{
var poly_lat = doc[0].placemarks[i].Polygon[0].outerBoundaryIs[0].coordinates[j].lat;
var poly_lon = doc[0].placemarks[i].Polygon[0].outerBoundaryIs[0].coordinates[j].lng;
arr_cord[j] = new google.maps.LatLng(poly_lat,poly_lon);
//arr_cord[i] = poly_lat + "," + poly_lon;
//;
}
//alert(arr_cord);
arr_polyoptions[i] = { path: arr_cord,strokeColor: "#FF0000",strokeOpacity: 0.8,strokeWeight: 2,fillColor: "#0000FF",fillOpacity: 0.6 };
//polygons[i] = new google.maps.Polygon(cord_polyOptions);
styles[i] = doc[0].placemarks[i].styleID;
//alert(doc[0].placemarks.polygon.outerBoundaryis.LinearRing.coordinates);
}
Now for checking through the polygons I use :
for(var curr = 0;curr<arr_polyoptions.length;curr++)
{
//var curr_polygon = polygons[curr];
console.log(arr_polyoptions[curr]);
var curr_polygon = new google.maps.Polygon(arr_polyoptions[curr]);
//var isWithinPolygon = curr_polygon.containsLatLng(place.geometry.location);
var isWithinPolygon = curr_polygon.containsLatLng(place.geometry.location);
alert("isWithinPolygon = " + isWithinPolygon);
if(isWithinPolygon == 'true')
{
alert(styles[curr]);
break;
}
}
But the code produces the error Object # has no method 'containsLatLng' on the line var isWithinPolygon = curr_polygon.containsLatLng(place.geometry.location);
Is there anyone out there who can help me in this problem? Thank you in advance
On logging the curr_polygon object,the result in console is
ui
fillColor: "#0000FF"
fillOpacity: 0.6
gm_accessors_: Object
gm_bindings_: Object
latLngs: hg
b: Array[1]
0: hg
b: Array[2418]
[0 … 99]
0: N
jb: 41.8019457978553
kb: -87.62588976266039
if it helps