I've created a function to return latitute and longitude.
The problem is that alert('outside:')
is triggered before geocoder.geocode
.
Looking at this similar example, this function should work.
function getLatLng(geocoder, adr) {
var latLng = '';
geocoder.geocode({
address: adr}, function(results, status){
if (status == google.maps.GeocoderStatus.OK && results.length) {
latLng = results[0].geometry.location;
alert('inside: ' + latLng); // This works
}
}
);
alert('outside: ' + latLng); // This shows NULL
return latLng;
}
So what do I need to to in order to return latlng value?