This is not a 'how-to' kind of question, but rather 'please help me find the bug' kind.
Use-case: The user is free to draw a polygon on the map and search for markers within its bounds. Using Google Maps API v3.
Here is the JS:
function drawPolygon() {
var polygon = new google.maps.Polygon({
paths: [],
strokeColor: '#006A4D',
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: 'green',
fillOpacity: 0.35,
editable: true,
draggable: true,
clickable: true
});
searchWithinPolygon(polygon);
return polygon;
}
function searchWithinPolygon(polygon) {
var markers_within_polygon = [];
var marker_latlng;
console.log('1');
for (var i = 0; i < markers.length; i++) {
marker_latlng = new google.maps.LatLng(markers[i].position.lat(), markers[i].position.lng());
if (google.maps.geometry.poly.containsLocation(marker_latlng, polygon)) {
console.log('2');
markers_within_polygon.push(markers[i]);
}
}
plotData(map, markers_within_polygon);
}
Problem: For some reason I get an error: "TypeError: b.get is not a function" in main.js (clearly a function that belongs to google maps API) in browser console in this line:
if(google.maps.geometry.poly.containsLocation(marker_latlng, polygon)){
Additional Info: The browser console is printing "1" but not "2". The above error is right after "1".
I am unable to tell why this is failing. Please help. Thanks!
Unfortunately I am unable to post a screenshot because my reputation is too low.