javascript - Problem getting distanceFrom in Google Map api -


i try distance between 2 points using google maps api,

function load_points(){         var geocoder = new gclientgeocoder();          var firstzip, secondzip;         geocoder.getlatlng(document.getelementbyid("firstzip").value, function(point) {           if (!point) {              alert("this point not geocoded");             } else {              firstzip = point;             var marker = new gmarker(point);             map.addoverlay(marker);            }         });          geocoder.getlatlng(document.getelementbyid("secondzip").value, function(point) {           if (!point) {              alert("this point not geocoded");             } else {               secondzip = point;              var marker = new gmarker(point);                          map.addoverlay(marker);             }         });          alert(new glatlng(firstzip).distancefrom(new glatlng(secondzip)));      } 

the problem when try seems first executed alert , after geocoding part, , of course distancefrom method fails because value of firstzip , secondzip undefined. knows how solve it?

the getlatlng function asynchronous, need wait both calls return before attempt use firstzip , secondzip variables.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -