简体   繁体   中英

Google Maps v3 - How can I get all the markers?

with this code I can show on the map just the first 20 markers obtained with the research.

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

But I would show on the map ALL the markers, at the same time and not just the first twenty. How can I do that?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM