在這裏,我有一個代碼,用於在框中搜索時顯示Google地點對象。超過查詢限制
所以:
function findPlaces(boxes,searchIndex) {
var request = {
bounds: boxes[searchIndex],
types: ["museum"]
};
// alert(request.bounds);
service.nearbySearch(request, function (results, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
alert("Request["+searchIndex+"] failed: "+status);
return;
}
// alert(results.length);
document.getElementById('side_bar').innerHTML += "bounds["+searchIndex+"] returns "+results.length+" results<br>"
for (var i = 0, result; result = results[i]; i++) {
var marker = createMarker(result);
}
searchIndex++;
if (searchIndex < boxes.length)
findPlaces(boxes,searchIndex);
});
}
但如果盒子是空的,我得到錯誤:Request[i].failed ZERO_RESULT
我的第一個問題是如何在這一跳,所以如何去下一個框,這只是跳becouse沒有結果
還有一段時間我得到OVER_QUERY_LIMIT - 我該如何解決這個問題?
更新:我嘗試像THET需要解決的問題卻又是一樣的:
function findPlaces(boxes,searchIndex) {
var request = {
bounds: boxes[searchIndex],
types: ["museum"]
};
// alert(request.bounds);
service.nearbySearch(request, function (results, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
//JUMP TO THE NEXT
searchIndex++;
}
// alert(results.length);
document.getElementById('side_bar').innerHTML += "bounds["+searchIndex+"] returns "+results.length+" results<br>"
for (var i = 0, result; result = results[i]; i++) {
var marker = createMarker(result);
}
//WAIT 3000 TO THE NEW REQUEST
setTimeout(function() {
alert('hello');
}, 3000);
searchIndex++;
if (searchIndex < boxes.length)
findPlaces(boxes,searchIndex);
});
}
查看這個答案** ** OVER_QUERY_LIMIT的:http://stackoverflow.com/questions/3529746/over-query-limit - 使用谷歌地圖 –
不,我達到每秒查詢,所以我必須寫一些東西等待之前致電下一個查詢 – roaddev
也許你可能會收到** OVER_QUERY_LIMIT **睡眠/等待像'setTimeout(FN,1000 )'這會等待1秒鐘,然後再次調用該函數。 –