I have a javascript function which should return a geocoding for a string:
function codeAddress(address) {
var result = (new google.maps.Geocoder()).geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
return String(results[0].geometry.location.Ya)+','+String(results[0].geometry.location.Za)
} else {
return status;
}
});
console.log(result);
return result
}
However it returns "undefined". I understand the bug here,i.e, since javascript is asynchronous, its returning from the function codeAddress even before function(results, status) gets fully executed. But I need to know whats the solution here and the best practice.