How can I call a JS function within a click event, and is this function inside another?
Follow the code:
function setPin(geocoder, resultsMap, address, i) {
geocoder.geocode({
'address': address
}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
var lat = results[0].geometry.location.lat(); //obtem latitude
var long = results[0].geometry.location.lng(); //obtem longitude
var cod = names[i].split(',')[0];
var name = names[i].split(',')[1];
var novaInfoWindow = criaInfoWindow(cod, name, address);
var marker = new google.maps.Marker({
map: resultsMap,
position: results[0].geometry.location
});
marker.addListener('click', function() {
novaInfoWindow.open(resultsMap, marker);
});
function checkInPolygon(polygon) {
myresult = google.maps.geometry.poly.containsLocation(results[0].geometry.location, polygon);
}
} //status
}); //geocoder.geocode
}//setPin
The click event calling the function is like this: (remembering that the event is inside another function - poly()
)
polygon.addListener('click', checkInPolygon(polygon));
The following error returns me:
Uncaught ReferenceError: checkInPolygon is not defined
I know the reason for this error is because the checkInPolygon
function is inside two other functions, but I do not have enough practice to know how to access this function. Any ideas?