I'm trying to get return values for placing a google maps marker on land (continent) or on water (oceans). When I try console log, I should get true for placing the marker on land, and false for placing it on water. However, the marker's value seems to lag behind by one move: For example, placing it on water will return true, then placing it on land will return false, but placing it on land again will return true again.
How can obtain the right value of the "result" variable inside the geocoder callback function?
Why am I getting lagging results and how can it be fixed?
Thank you.
var result = true;
function checkMarkerOnLand(event) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
"latLng" : event.latLng
}, function(results, status) {
if (status !== google.maps.GeocoderStatus.OK) {
result = false;
//return result;
} else {
result = true;
//return result;
}
});
return result;
}