How to get 20+ result from Google Places API?
Asked Answered
K

7

25

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 get more results. In the API doc it is mention that it will return 20 result but I would like to know is there any way I can get more data or I have to create my own database for that?
Also what I found in the API is that it does not have all the ATM's for India. The information is also not accurate for some of the locations. So Please suggest me some idea for that I should use my own database or not?
I know that I can register places in the Google Places but there is the problem that every time it returns only 20 result. If anyhow this problem is resolved then it will be great to use the Places API..

Please kindly help me.....

Kindling answered 8/3, 2012 at 7:35 Comment(8)
possible duplicate of Google Places API : Number of resultsSpecial
What are you trying to provide for your users that needs more than 20 results at a time? If you provide more details about what you are trying to achieve I may be able to provide a better solution for you.Tandi
@ChrisGreen, I would like to provide the near by ATM's to my users but its not that only 20 nearest. I have seen the Places App provided by Google in that when you reach at the end of the list of ATM's (in my case) it shows more results. I wish to display 40-50 results to the user. And the Data which is provided by Google Places API is not accurate for India because I found that lots of ATM's & Banks near by my area is not available in the list. I done some R&D in that and found that i can add places to Places API or I can use my own DB too. What you suggest I should use? I am very confused..Kindling
The Places App does not use the Places API therefore it is not limited to 20 results. Try the workaround described below to help find more ATM's. If you are still not having any luck it may be because Google has no data for that area. You can perform a Place Report Request to add the data your self or you can upload bulk data: google.com/local/add/g?gl=US&hl=en-US#uploadfeed Instead of showing your users a large list of all ATM's why not provide them with a selection of banks to search for ATM's for. Using bank name as keyword in your Places Search Request.Tandi
@ChrisGreen, Thank you so much for this link & your suggestion. But one more thing i would like to know is that if i upload the data then it will be available through Places API only right? I wish to add more services like Food, Restaurants, Cafes & many more. So in some services i wish to show more than 20+ results.Kindling
If adding places through the bulk upload form, after verification uploaded places will be available on all Google maps products. (Verification process can take up to a week). If adding places through the Places API using Place Report Requests, places will be available to your API key instantly, and on all other Google Maps products after verification.Tandi
The Places API will not return more than 20 places at a time so you will have to work around this when building your application.Tandi
But what other option to resolve this? Do you have any idea/suggestion for this? Because I want to get near by places which i can get from Places API only & it gives me 20 results only.Kindling
T
31

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.

Tandi answered 9/3, 2012 at 1:20 Comment(3)
Param for accessing next 20 result should be "pagetoken" with value of next_page_token.Odell
is this applicable even for paid users ?Dive
@Chris Can you please let me know how to fetch more than 60 places, is it available in paid api?Chilung
B
21

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"

Barmaid answered 13/9, 2012 at 13:12 Comment(4)
this is great. but what if i am using the android api? does it give the next page option? i can't find it.Asphyxiate
@ Malik Saad Bin Tariq yes you can find it this way in android google map api alsoBarmaid
can we got the all 60 records at once?Hazlitt
You can get 60 results making 3 API calls, not one.Socinian
B
6

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

    }
Booher answered 10/10, 2012 at 17:57 Comment(2)
where is PlaceList class here?Matterhorn
Thank you - you solved my problem. The next page is not available immediately! I saw your "Thread.sleep(4000);" and realized why pagetoken only sometimes works in my code - usually the code is too quick in requesting the next page. Of course when I debugged it by steping through it always worked.Nestor
H
0

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 –

Hungry answered 27/4, 2012 at 11:10 Comment(0)
S
0

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.

Sulphurbottom answered 15/5, 2013 at 7:28 Comment(0)
S
-1

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
Suppositious answered 24/5, 2016 at 6:22 Comment(1)
it is pagetoken= not next_page_token=Citron

© 2022 - 2024 — McMap. All rights reserved.