Here I have a code to show me google places objects when search in boxes.
So:
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);
});
}
but if box is empty I get error: Request[i].failed ZERO_RESULT
My first question is How to JUMP over this, so how go to next box and this just jump becouse there is no results
Also some time I get OVER_QUERY_LIMIT - How I can solve this problem?
UPDATE: I TRY LIKE THET TO SOLVE PROBLEM BUT AGAIN IS THE SAME:
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);
});
}
service.nearbySearch(request, function (results, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
// you probably don't even need the test for 'ZERO_RESULT' just test
// your index against the boxes array for more items to search since
// status could be a different error
if((status == 'ZERO_RESULT') && (++searchIndex < boxes.length)){
findPlaces(boxes,searchIndex);
}else{
return;
}
}else{
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);
}
if (++searchIndex < boxes.length)
findPlaces(boxes,searchIndex);
}
});
Ok, I didn't see that you wanted to output a zero result in your sidebar, in this case you don't need to check for status OK since results will have nothing anyhow. Try this:
service.nearbySearch(request, function (results, status) {
document.getElementById('side_bar').innerHTML += "bounds["+searchIndex+"] returns "+results.length+" results<br>"
for (var i = 0;i<results.length; i++) {
var marker = createMarker(results[i]);
}
if (++searchIndex < boxes.length)
setTimeout(findPlaces(boxes,searchIndex),500);
});
EDIT - Maybe this:
service.nearbySearch(request, function (results, status) {
if(status == 'OVER_QUERY_LIMIT'){
setTimeout(findPlaces(boxes,searchIndex),1000);
}else{
document.getElementById('side_bar').innerHTML += "bounds["+searchIndex+"] returns "+results.length+" results<br>"
for (var i = 0;i<results.length; i++) {
var marker = createMarker(results[i]);
}
if (++searchIndex < boxes.length)
setTimeout(findPlaces(boxes,searchIndex),1000);
}
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加