そのため、情報を解析し、複数の住所でジオコードをクエリしています。それを行う最善の方法が何であるかは完全にはわかりません。これが私がやろうとしていることです。
for($j = 0; $j < $rawArray.length; $j++){
$baseStr = $addresNum != 'empty' ? $rawArray[$j][$addresNum] + ' ': '';
$baseStr += $addresStr != 'empty' ? $rawArray[$j][$addresStr] + ' ': '';
$baseStr += $addresDiv != 'empty' ? ', ' + $rawArray[$j][$addresDiv] : '';
$baseStr = ($baseStr.toLowerCase().indexOf("qc") >= 0 || $baseStr.toLowerCase().match(/qu[e-é]bec/) ? $baseStr : $baseStr + ", Qc");
console.log("Looking for: " + $baseStr.match(/\w\d\w([ ])*\d\w\d/i)[0]);
$baseStr = $baseStr.match(/\w\d\w([ ])*\d\w\d/i)[0];
$geocoder.geocode({
address: $baseStr
}, function(locResult, status) {
$arrayCoords[$j] = new Array();
if (status == google.maps.GeocoderStatus.OK) {
$arrayCoords[$j][0] = locResult[0].geometry.location.lat();
$arrayCoords[$j][1] = locResult[0].geometry.location.lng();
}else {
$arrayCoords[$j][0] = '';
$arrayCoords[$j][1] = '';
}
});
console.log("found: " + $arrayCoords[$j][0] + $arrayCoords[$j][1]);
}
ここで、配列にデータを入力して操作するのは良い考えだと思いました。だから私はこれをしました:
$timeout = setInterval(function()
{
for($j = 0; $j < $rawArray.length; $j++){
console.log($globalGoogleArray[$j]);
}
if($globalGoogleArray.length == $rawArray.length)
{
console.log($globalGoogleArray);
//TODO: stopTimer();
}
}, 100);
そしてその直前にconsole.log("found: " + $arrayCoords[$j][0] + $arrayCoords[$j][1]);
追加した$globalGoogleArray[$j] = $arrayCoords[$j][0] + ", " + $arrayCoords[$j][1];
値を入力できる場合は$globalGoogleArray
、タイマーを停止して、配列の内容を操作する関数をトリガーできます。これは最善の方法ではないかもしれませんが、私は提案を受け付けていますが、それでも、私が望むもので終わるわけではありません. タイマーは の上に配置され、for
その中の console.log は undefined を返すだけで、for
(this one: console.log("found: " + $arrayCoords[$j][0] + $arrayCoords[$j][1]);
) の console.log が出力すると予想されるものを出力します。
globalGoogleArray でジオコードの出力を取得できない理由について、誰か教えてもらえますか?