2013-08-31 92 views
0

在這裏,我有一個代碼,用於在框中搜索時顯示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); 
    }); 
} 
+0

查看這個答案** ** OVER_QUERY_LIMIT的:http://stackoverflow.com/questions/3529746/over-query-limit - 使用谷歌地圖 –

+0

不,我達到每秒查詢,所以我必須寫一些東西等待之前致電下一個查詢 – roaddev

+0

也許你可能會收到** OVER_QUERY_LIMIT **睡眠/等待像'setTimeout(FN,1000 )'這會等待1秒鐘,然後再次調用該函數。 –

回答

0
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); 
    } 
}); 

好吧,我沒有看到你在你的側邊欄要輸出一個結果,在這種情況下,您不需要檢查狀態,因爲結果不會有任何結果。試試這個:

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); 
}); 

編輯 - 也許這:

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); 
    } 
}); 
+0

hm,請在這裏嘗試http://jsbin.com/EVEWOta/43 - 從巴黎到索非亞挑選距離10米...? – roaddev

+0

或從Dnever到Oklahoma只需10mi – roaddev

+0

但是,再次嘗試10mi從巴黎ti索非亞......地方只是在開始,然後不會顯示....也非常感謝幫助我......我更新這裏有你的答案:http://jsbin.com/EVEWOta/43 – roaddev