I\'ve been struggling with this for a few hours now, and even after reading several examples on Stack I\'ve been unable to get this working. It doesn\'t help that I\'m a JS
Your problem is, that you didn't connect the callback to the return. As the geocode()
function itself is already asynchronous, the return
doesn't have any effect there. Instead you have to pass the values you are returning here directly to the callback-function. Like this:
function getLocationData(position, callback) {
geocoder = new google.maps.Geocoder();
var location = 'Billings,MT';
if( geocoder ) {
geocoder.geocode({ 'address': location }, function (results, status) {
if( status == google.maps.GeocoderStatus.OK ) {
callback(results[0]);
}
});
}
}