Reputation: 1302
I'm working with google map api V3 and want to get location for some address by using next function:
function findAddress(address) {
var geocoder = new google.maps.Geocoder();
var addrLocation = "";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
addrLocation = "Location is: " + results[0].geometry.location;
} else {
addrLocation = "Not found"; }
});
return addrLocation;
}
Then I'm trying to call findAddress function:
function SomeFunction(){
alert(findAddress("New York"));
}
To my logic, that alert should return 'addrLocation' value, but instead it returns blank message. What am I doing wrong?
Upvotes: 0
Views: 1064
Reputation: 207501
You can not return a value from an asynchronous call, going to find a dupe since this is asked hourly.
Upvotes: 3