0

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?

2

1 Answer 1

3

You can not return a value from an asynchronous call, going to find a dupe since this is asked hourly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.