I have this function. I seem not to understand how it exactly works. Because I want to return returnlatlang
with this function. But it simply does not work.
var geocoder = new google.maps.Geocoder();
function codeAddress(address) {
var returnlatlang;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
returnlatlang = results[0].geometry.location;
console.log(returnlatlang); // this is defined.
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
console.log(returnlatlang); // this is undefined.
return returnlatlang;
}
How does scope work in this case?