-2

My function is like this.

function getLatLong(address){
    var latitude="";
    var geocoder =  new google.maps.Geocoder();

    geocoder.geocode( { 'address': address}, function(results, status) {
        latitude = results[0].geometry.location.lat();
        alert(latitude);
});
   return latitude;
}


  alert(getLatLong(co));

when i call this function I get empty result but the alert in the function returns the latitude.what the problem?

1

1 Answer 1

0

I think the ops answer in this question might help :

Google maps geocode API V3 not returning result in javascript function

As you can see in the solution, the op uses a callback from geocoder.geocode.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.