javascript - Google map geocoder, accessing global variable in it -


I have to find out from the address, and I want to load them all into a global array varibale, what do I do here I am

 ] + ',' + location [i] ['district'] + ',' + location [i] ['country']; Var Pajecodair = New google.maps.Geocoder (); Pgeocoder.geocode ({'address': paddress}, function (result, status) {if (position == google.maps.GeocoderStatus.OK) {storelatlong [i] = results [0] .geometry.location;}}) ; } Alert (Stoltlonglong);   

But it always returns to length 0, if I warn inside the Geocoder function, then it gives the Letlong penalty, a global variable from within the GeoOders to gather data There is no other way of thanking

I think the problem is that until you respond to google No one is defined unless there is any other way to get it, with the closure of it Do it,

  pgeocoder.geocode ({'address': paddress}, (function (index) {return function (result, condition) {if (status) == google.maps.GeocoderStatus .OK) {Storelatlong [index] = Result [0] .geometry.location;}}} (i)));    

Comments