我無法顯示所有來自谷歌Places API的請求的結果..谷歌Places API的:不能夠顯示所有的搜索結果
var Latlng = new google.maps.LatLng(Latitute, Longitute);
map = new google.maps.Map(document.getElementById('map_canvas'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: Latlng,
zoom: 10});
var request = {location: Latlng,types: [type]};
var service = new google.maps.places.PlacesService(map);
service.search(request, callback);
}
function callback(results,status,pagination) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
if (pagination.hasNextPage) {
pagination.nextPage(); }}}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({map: map,zIndex: 100,position: place.geometry.location});
var request = {reference : place.reference,};
service = new google.maps.places.PlacesService(map);
service.getDetails(request, function detailsDisplay(details, status){
if (status === google.maps.places.PlacesServiceStatus.OK) {
console.log(status);
$('#placesdata').append('<tr><td><a href='+details.url+'>' + details.name+ '</a></td></tr>');
} else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
setTimeout(function() {
createMarker(place);
}, 200);}});} };
我使用分頁並獲得60倍的結果,但只能顯示20。 。和40使用settimeout()函數...獲取以下錯誤:未捕獲TypeError:無法讀取null的屬性「長度」。任何線索?
仍然無法顯示60個結果...任何其他方式 – teekib
你現在得到什麼錯誤?在請求下一批之前,您需要添加睡眠功能,我最後一次錯過了。就像文檔所說:「nextPage()函數將返回下一組結果。執行搜索之後,您必須等待兩秒鐘,然後結果的下一頁纔可用。」也看看這裏:http://stackoverflow.com/questions/11665684/more-than-20-results-by-pagination-with-google-places-api爲同一個問題的答案。 – kaskader
yeahh ..謝謝你kaskader – teekib