0
How can I call a JS function inside a click event, and this function is inside another?
Follows 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 looks 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 mistake is because the function checkInPolygon
is within two other functions, but I don’t have enough practice to know how to access this function. Any idea?
It is necessary somehow to invoke
setPin
and then invokecheckInPolygon
, but in your case she’s still ingeocoder.geocode
. Why do I need her straight?– BrTkCa
@Lucascosta this function will check for me if the locations that are being shown on the map are inside a polygon that was drawn on the map. That is why you are inside another function: there is a function where you create the Poligono (
poly()
), and after it is completed (eventpolygoncomplete
), recovers its vertices and within this event, there is still the event ofclick
that would enable me to know "who" is inside the Opoligono through this function that I am trying to access...– Z..