46

I want to develop a map application which will display the banks near a given place.

I use the Places library to search and everytime it just return 20 results. What should I do if I want more results?

7 Answers 7

26

UPDATE: Since I originally wrote this answer, the API was enhanced, making this answer out of date (or, at least, incomplete). See How to get 20+ result from Google Places API? for more information.

ORIGINAL ANSWER:

The documentation says that the Places API returns up to 20 results. It does not indicate that there is any way to change that limit. So, the short answer seems to be: You can't.

Of course, you might be able to sort of fake it by doing queries for several locations, and then merging/de-duplicating the results. It's kind of a cheap hack, though, and might not work very well. And I'd check first to make sure it doesn't violate the terms of service.

3
  • Thank you for your answer. That hack ever come to my mind too :) I check the documentation again and can't find a parameter to change that limit.And I just wonder if there is a better source to get the results? Commented Aug 7, 2011 at 2:42
  • @Trott, Hi Trott, I am also facing the same issue. How can i fetch more data? If you have seen the Places app by Google it will fetches data at the end of scrolling in the Listview. So is it like that its firing the query again? If you have any suggestion please kindly help... Commented Mar 8, 2012 at 6:35
  • @Scorpion, you could try something like, while radius < max_limit radius++ search, i.e., increase the radius, send a query, and at the end you remove the duplicates. It is going to help a little, but the way it is currently, Google Places API is useless. Commented May 31, 2012 at 11:25
20

Now it is possible to have more than 20 results (but up to 60), a parameter page_token was added to the API.

Returns the next 20 results from a previously run search. Setting a page_token parameter will execute a search with the same parameters used previously β€” all parameters other than page_token will be ignored.

Also you can refer to the accessing additional results section to see an example on how to do the pagination.

2
  • 10
    Worth adding is that using this method the max number of results is 60, according to stackoverflow.com/a/9627664/1565279 . Commented Feb 23, 2013 at 14:11
  • @HischT, yes, I am aware about the limitation, for me a pitty, but I forgot to write that when I've posted the answer. Edited, thanks! :) Commented Mar 1, 2013 at 9:41
6

In response to Eduardo, Google did add that now, but the Places documentation also states:

The maximum number of results that can be returned is 60.

so it still has a cap. also FYI, there is a delay for when the "next_page_token" will become valid, as Google states:

There is a short delay between when a next_page_token is issued, and when it will become valid.

and here is the official Places API docs:

https://developers.google.com/places/documentation/

2

Here's code sample that will look for additional results

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Web.Script.Serialization;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var url = $"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={args[0]}&radius={args[1]}&type=restaurant&keyword={args[2]}&key={args[3]}";

            dynamic res = null;
            var places = new List<PlacesAPIRestaurants>();
            using (var client = new HttpClient())
            {
                while (res == null || HasProperty(res, "next_page_token"))
                {
                    if (res != null && HasProperty(res, "next_page_token"))
                    {
                        if (url.Contains("pagetoken"))
                            url = url.Split(new string[] { "&pagetoken=" }, StringSplitOptions.None)[0];
                        url += "&pagetoken=" + res["next_page_token"];

                    }
                    var response = client.GetStringAsync(url).Result;
                    JavaScriptSerializer json = new JavaScriptSerializer();
                    res = json.Deserialize<dynamic>(response);
                    if (res["status"] == "OK")
                    {
                        foreach (var place in res["results"])
                        {
                            var name = place["name"];
                            var rating = HasProperty(place,"rating") ? place["rating"] : null;
                            var address = place["vicinity"];
                            places.Add(new PlacesAPIRestaurants
                            {
                                Address = address,
                                Name = name,
                                Rating = rating
                            });
                        }
                    }
                    else if (res["status"] == "OVER_QUERY_LIMIT")
                    {
                        return;
                    }
                }
            }
        }

        public static bool HasProperty(dynamic obj, string name)
        {
            try
            {
                var value = obj[name];
                return true;
            }
            catch (KeyNotFoundException)
            {
                return false;
            }
        }
    }
}

Hope this saves you some time.

1

Not sure you can get more.

The Places API returns up to 20 establishment results.

http://code.google.com/apis/maps/documentation/places/#PlaceSearchResponses

1
  • 4
    @andi Now you can. But when I responded over two years ago you couldn't. If you voted me down for that... very uncool. But I understand ;-) Commented Oct 21, 2013 at 12:36
1

You can scrape Google Places results and follow pagination to get 200-300 places for a specific location (from 10 to 15 pages of search results).

Alternatively, you can use SerpApi to access extracted data from Google Places. It has a free trial.

Full example

# Python package: https://pypi.org/project/serpapi
from serpapi import Client as SerpApiClient
import os

params = {
    "engine": "google",
    "q": "restaurants",
    "location": "United States",
    "tbm": "lcl",
    "start": 0
}

serpapi = SerpApiClient(api_key=os.environ['SERPAPI_API_KEY'])
search = serpapi.search(params)

for local_result in search.get('local_results', []):
  print(
      f"Position: {local_result['position']}\nTitle: {local_result['title']}\n"
  )

for page in search.yield_pages():
  print(f"Current page: {page.get('serpapi_pagination', {}).get('current')}\n")

  for local_result in page.get('local_results', []):
    print(
        f"Position: {local_result['position']}\nTitle: {local_result['title']}\n"
    )

Output

Current page: 11

Position: 1
Title: Carbone

Position: 2
Title: Elmer's Restaurant (Palm Springs, CA)

Position: 3
Title: The Table Vegetarian Restaurant

...

Disclaimer: I work at SerpApi.

0

If the problem is that not all banks that exists inside the search radius might not be returned, I would suggest limiting the search radius instead of issuing multiple automated queries.

Set the radius to some value in which it is impossible to get more then 20 (60) banks. Then make it easy (GUI-wise) for the user to hammer out more queries manually - sort of painting a query.

Returning thousands of banks in a larger region will likely require you to rely on your own database of banks - which could be achievable if you work on it systematically.

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.