I have a function, getLatLong()
that I use throughout my code. I want it to return the latitude and longitude from a given address.
function getLatLong(address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address, 'region': 'uk' }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
return [lat, lng];
} else {
return ("Unable to find address: " + status);
}
});
}
Wanting to be able to do getLatLong("London SW1A 1AA");
I seem to not be able to get it to work. It constantly returns undefined
. After researching a bit, I see that I have to use a callback, but I cannot for the life of me figure out how to do it.