そこで、クラスの API マッシュアップを作成しています。現在、Google Maps API から json レスポンスを取得しています。for ループを使用して、応答から 5 つのウェイポイントを取得しています。私が修正しようとしている問題は、座標の一部がデッド スペースにあり、それらに関連付けられた画像がないことです。4回の反復ごとにajax呼び出しを行いたいのですが、画像がない場合は、画像が見つかるまで反復し、中断したところに戻ります。while ループを使用して呼び出しを行ってみましたが、調整が成功すると、while ループ変数が true に設定され、while ループから抜け出し、for ループに戻り、反復します。次の「ウェイポイント」へ。今のところエラーは発生していません。サイトがタイムアウトしています。おそらく呼び出しが多すぎますか? 多分、私'
// so this for loop divides the hundreds of steps by 1/4 of the total length.
for (i=0; i<polyPoints.length; i+=quarters) {
// gets the coords for the current iteration.
var lat = polyPoints[i][0];
var lng = polyPoints[i][1];
var hasPic = false;
var origI = i;
//while loop runs through and checks to see if the coordinate has pictures at it.
while (hasPic == false){
$.ajax({
type : "GET",
dataType : "jsonp",
ajaxI: i,
url: 'https://api.instagram.com/v1/media/search?lat='+lat+'&lng='+lng+'&distance=5000&access_token='+token,
success: function(data){
i = this.ajaxI;
//if null,increases the iteration by one, and then runs through the loop again, checking the next coordinate? I hope.
if(typeof data.data[0] === "undefined" || data.meta.code == 400){
i++;
console.log("i increased to "+i);
}else{
//if the pic is there then it assigns a random picture from the result to the images array.
images.push(data.data[Math.floor(Math.random() * data.data.length)].images.low_resolution.url);
//sets while loop to stop
hasPic = true;
//loads the current iterations coordinates for the later for loop to create markers.
waypoints.push([lat,lng]);
}
}, //data.data[0].images.low_resolution.url
error: function(data){
i = this.ajaxI;
i++;
//images.push(img/test.jpg");
}
}).responseText;
}//waypoints.push([lat,lng]);
//resets the i back to the original iteration before it got increased
i = origI;
}