How to get 20+ result from Google Places API?

后端 未结 7 1818
一整个雨季
一整个雨季 2020-12-02 10:22

I am developing an app in which I am getting the list of ATM\'s near by the user. For that I am using Google Places API, but every time it returns 20 result only. I want to

相关标签:
7条回答
  • 2020-12-02 10:35

    You can get the more results from next page token:

    https://maps.googleapis.com/maps/api/place/textsearch/json?query=[your search key word]&location=latitude,longitude&radius=value&key=[your API key]&next_page_token=next_page_token value
    
    0 讨论(0)
  • 2020-12-02 10:37

    On the Google places page on: https://developers.google.com/places/documentation/search Under 'Radar Search Requests' it states that using: https://maps.googleapis.com/maps/api/place/radarsearch/output?parameters you get 200 results using this call, but note that each call uses 5 requests against your quota.

    0 讨论(0)
  • 2020-12-02 10:42

    Please try below url with below parameters

    URL = "http://www.google.com/maps?q=restaurant&ie=UTF8&hl=en&sll=0.000000,0.000000&sspn=0.000000,0.000000&vps=3&sa=N&start=20"

    Where start = No of results say for instance start from 0 or 10 0r 20 –

    0 讨论(0)
  • 2020-12-02 10:44

    Google API fetches the 20 Result in one page suppose you want to use the next page 20 result then we use the next_page_token from google first page xml as a result.

    1) https://maps.googleapis.com/maps/api/place/search/xml?location=Enter latitude,Enter Longitude&radius=10000&types=store&hasNextPage=true&nextPage()=true&sensor=false&key=Enter Google_Map_key

    in second step you use the first page's next_page_token data

    2)https://maps.googleapis.com/maps/api/place/search/xml?location=Enter Latitude,Enter Longitude&radius=10000&types=store&hasNextPage=true&nextPage()=true&sensor=false&key=enter google_map_key &pagetoken="Enter the first page token Value"

    0 讨论(0)
  • 2020-12-02 10:58

    You can do this by using Google API JAVA Client - Here is an example using the java client for getting all the 60 results.

    public PlacesList search(double latitude, double longitude, double radius, String types)
                throws Exception {
    
            try {
    
                HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
                HttpRequest request = httpRequestFactory
                        .buildGetRequest(new GenericUrl("https://maps.googleapis.com/maps/api/place/search/json?"));
                request.getUrl().put("key", YOUR_API_KEY);
                request.getUrl().put("location", latitude + "," + longitude);
                request.getUrl().put("radius", radius); 
                request.getUrl().put("sensor", "false");
                request.getUrl().put("types", types);
    
                PlacesList list = request.execute().parseAs(PlacesList.class);
    
                if(list.next_page_token!=null || list.next_page_token!=""){
                             Thread.sleep(4000);
                             /*Since the token can be used after a short time it has been  generated*/
                    request.getUrl().put("pagetoken",list.next_page_token);
                    PlacesList temp = request.execute().parseAs(PlacesList.class);
                    list.results.addAll(temp.results);
    
                    if(temp.next_page_token!=null||temp.next_page_token!=""){
                        Thread.sleep(4000);
                        request.getUrl().put("pagetoken",temp.next_page_token);
                        PlacesList tempList =  request.execute().parseAs(PlacesList.class);
                        list.results.addAll(tempList.results);
                  }
    
                }
                return list;
    
            } catch (HttpResponseException e) {
                return null;
            }
    
        }
    
    0 讨论(0)
  • 2020-12-02 11:00

    As per the documentation:

    https://developers.google.com/places/web-service/search#PlaceSearchResponses

    EDIT: Place API now supports pagination of up to 60 results. See below for details.

    The Places API will return up to 20 establishments per query; however, each search can return as many as 60 results, split across three pages. If your search will return more than 20, then the search response will include an additional parameter — next_page_token. Pass the value of next_page_token to the page_token parameter of a new place search to see the next set of 20 results.

    There is also strict terms of service that specify you cant Pre-Fetch, Cache, or Store Content unless it is the content identifier or key you are permitted to store i.e. reference token from a places search:

    https://cloud.google.com/maps-platform/terms/?_ga=#3-license

    In regards to not being able to find ATM's in India. All places are categorized under the type establishment until Google has enough metadata about a place to categorize it under more specific place types like ATM, cafe, bar etc. A work around that may find more results is to use the keyword parameter in your request with something like 'ATM', 'bank' or 'finance' as the value. As per the documentation:

    https://developers.google.com/places/web-service/search#PlaceSearchRequests

    The keyword parameter is matched against all available fields, including but not limited to name, type, and address, as well as customer reviews and other third-party content.

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