アドレスから緯度経度を見つける必要があり、それらすべてをグローバル配列変数にロードしたいのですが、ここで私がやっていること
for(i=0; i<locations.length; i++){
var paddress = locations[i]['address'] +','+locations[i]['postal_code'] + ', ' +locations[i]['district'] + ',' + locations[i]['country'];
var pgeocoder = new google.maps.Geocoder();
pgeocoder.geocode( { 'address': paddress}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
Storelatlong[i] = results[0].geometry.location;
}
});
}
alert(Storelatlong.length);
しかし、それは常に長さ0を返します。ジオコーダー関数内でアラートを出すと、latlongがうまくいきます。ジオコーダー内からグローバル変数にデータを割り当てる他の方法はありますか、ありがとう