私はグーグルマップコードでこの問題に取り組んでいますが、実際にはアーキテクチャ上の問題です。リクエストが多すぎるため、ある時点でグーグルマップは応答を制限し、その時点で私は遅れて別のリクエストをしたいのですが、function2をもう一度呼び出すと「配列が定義されていません」と表示されます。
function1() {
var array = JSON.parse(xmlhttp.responseText);
for (i; i < length; < i++) {
function2(array[i].one, array[i].two);
}
function3() {
//render directions
}
function2(start, end) {
directionsService.route({
origin: start,
destination: end,
},
function (result, status) {
if (status == google.maps.DirectionsStatus.OK)
function3(result);
else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT)
var functionStr = "function2(array[i].one" + ',' + "array[i].two)";
setTimeout(functionStr, 5000);
});
}
}