How to get 20+ result from Google Places API?
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.
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;
}
}
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"