More than 20 results by pagination with Google Places API

前端 未结 2 1189
栀梦
栀梦 2020-12-19 12:24

Google\'s demo has this snippet to capture, by pagination, more than 20 results from place search:

    service.nearbySearch(request, resultList, function(sta         


        
相关标签:
2条回答
  • 2020-12-19 12:52

    here's how i've done it. I'm no guru on this stuff but here's my code.

    To start with you may need to strip the search call back out of function() into it's own function.

    I've got something like

    placesServiceClass.search(request, placesCallback);
    

    in your callback for restuls processing just do something like...

    function placesCallback(results, status, pagination) {
    
    // process the resutls  
    if (status == google.maps.places.PlacesServiceStatus.OK) {      
        for (var int = 0; int < results.length; int++) {    
            placesManager.addMarker(results[int], int);
        }
    
     } 
    
    if (pagination.hasNextPage) {
        sleep:2;
        pagination.nextPage();
    }
    

    The Google documentation states that you need to wait 2 seconds between next page calls, hence the sleep.

    The pagination.nextPage() calls the same callback, in my case placesCallback().

    Hope that helps

    0 讨论(0)
  • 2020-12-19 13:17

    Use Radar Search to get more results at once. You can then call PlacesService.getDetails() for more details on each of those places.

    0 讨论(0)
提交回复
热议问题