1

使用此代码,我可以在地图上仅显示通过研究获得的前 20 个标记。

        function initialize() {
            google.maps.visualRefresh = true;

            var mapOptions = {
              center: new google.maps.LatLng(41.900233,12.482132),
              zoom: 12,
              minZoom: 12,
              maxZoom: 16,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);


            var allowedBounds = new google.maps.LatLngBounds(
                 new google.maps.LatLng(41.77336,12.338805), 
                 new google.maps.LatLng(42.046233,12.675261)
            );

            var request = {
              bounds: allowedBounds,
              query: "ristorante"
              };

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

            function callback(results, status) {
              if (status == google.maps.places.PlacesServiceStatus.OK) {
                for (var i = 0; i < results.length; i++) {
                  var place = results[i];
                  createMarker(results[i]);
                }
              }
            }
            function createMarker(place) {
              var placeLoc = place.geometry.location;
              var marker = new google.maps.Marker({
                map: map,
                position: place.geometry.location
              });
            }
    }

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

但我会同时在地图上显示所有标记,而不仅仅是前二十个。我怎样才能做到这一点?

4

1 回答 1

0

You have to look for the third parameter in your callback:

function callback(results, status, pagination)...

That object can say if there is more results:

if (pagination.hasNextPage) {
  button.onClick = pagination.nextPage;
}

You have to decide the logic that make the call to the next page.

于 2013-07-06T19:25:09.530 回答