分页未定义 google 地图:显示多个 placeDetails

pagination undefined google maps : showing multiple placeDetails

我知道有很多关于这个的话题,但我找不到任何地方的错误。我正在构建一个移动应用程序,我正在尝试查找地点并将其名称显示在列表中。到目前为止,我的代码找到了所有我想要的地方并为所有这些地方创建了标记,但是当我尝试写名字时,它只写了 15-20。在地图上放置所有标记后,它开始写入名称。我搜索了解决方案并找到了一个使用 "pagination" 的解决方案,但是当我尝试它时,它给了我以下错误:"Uncaught TypeError: Cannot read property 'hasNextPage' of undefined"

这是我显示地点的代码:

var map;
var nextPlace;

function initialize() {
    //get the current position of the device
    navigator.geolocation.getCurrentPosition(search, failPosition,{timeout:10000});
    document.addEventListener("backbutton", onBackKeyDown, false); 

}


//called if the position is not obtained correctly
function failPosition(error) {
  alert("Your position is not available, please check your settings");

}

function search(position) {
  var lat = position.coords.latitude;
  var lon = position.coords.longitude;
  var myPos= new google.maps.LatLng(lat, lon);
  var mapOptions = {
    zoom: 12,
    center: new google.maps.LatLng(lat, lon)
  };
  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

   var Types=new Array();
   var ty = window.localStorage.getItem("types");
   if(ty[0]!='0')
   {
    Types.push('restaurant');
   }
   if(ty[1]!='0')
   {
    Types.push('bar');
   }
   if(ty[2]!=0)
   {
    Types.push('night_club');
   }
  var request = {
    location: myPos,
    radius: String(window.localStorage.getItem("distance")),
    types: Types

  };

  var service = new google.maps.places.PlacesService(map);
  service.radarSearch(request, callback);

}

function callback(results, status, pagination) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {

    getPlacesDetails(results); 

    if (pagination.hasNextPage) {
      sleep:2;
       pagination.nextPage();
}
  else
  {
     $('li').click(function()
        {
          alert("clicked");
        })
  }


}
}

function getPlacesDetails(places)
{
  for (var i = 0, place; place = places[i];i++) {
    var request = {
      placeId: places[i].place_id
     };
     nextPlace=places[i].place_id;
     var service = new google.maps.places.PlacesService(map);

      service.getDetails(request,placesCallBack); 

      marker = new google.maps.Marker({
      position: places[i].geometry.location,
      map: map,
      title: 'your location'});
      }

}

}
function placesCallBack(place,status){
   if (status== google.maps.places.PlacesServiceStatus.OK) {
        $('#PlacesList').append('<li data="'+place.place_id+'"><h1>'+place.name+'</h1></li>').listview('refresh');
      }

  }


function onBackKeyDown() {
       window.location='MainPage.html';
}

google.maps.event.addDomListener(window, 'load', initialize);

您正在使用 radar search, which retrieves up to 200 results and does not support pagination, that is for the other types of searches (NearbySearch, TextSearch),return 最多 60 个结果,每批 20 个..

Radar Search Requests

A Radar Search lets you search for places within a specified search radius by keyword, type or name. The Radar Search returns more results than a Nearby Search or Text Search, but the results contain fewer fields. You can call PlacesService.getDetails() to get more information about any of the places in the response.

The PlaceResult objects returned by radarSearch() include only the following properties:

  • geometry.location
  • place_id