在这里,我有一个代码向我展示在框中搜索时谷歌放置对象。
所以:
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
我的第一个问题是如何跳过这个,所以如何去下一个盒子,这只是跳转,因为没有结果
还有一段时间我得到 OVER_QUERY_LIMIT - 我该如何解决这个问题?
更新:我尝试解决问题,但还是一样:
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);
});
}