我无法显示从 Google 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 个结果,但使用 settimeout() 函数只能显示 20..和 40...得到以下错误:未捕获的类型错误:无法读取 null 的属性“长度”。有什么线索吗?