I am trying to use google places textSearch to discover all stores of certain brand (lets say Levi's) so I will iterate through the results by using next_page_token, but I seem to hit the issue of the max 60 results that are returned. Can this results be lifted somehow or does anyone know of another service that can provide this kind of results ?

有帮助吗?

解决方案

There is sadly no way around the 60-entry restriction other than clever polling on textsearch, and the results cannot be sorted. Your best solution would be nearbySearch. The API parameters are almost the same as textsearch, with three differences:

  • Your radius will be automatically set to 50km
  • rankby=distance allows you to sort results by distance from your location (you will see why this is important)
  • query becomes keywords and is no longer a true Google Maps search parameter - just a list of keywords

The results that come back are similar to the textSearch returns - and they come with a unique ID, which will come in handy as well.

How to scan everything

Scanning an area is pretty simple. You're limited to 60 results per query - so what we will do is sort by distance, so that we know for sure that our last result of the set is also the furthest. This allows you to build a maximum likely radius for your request - and the base your next search on this.

Here is a simulated result on photoshop. I ran a random request based on a point in France and mapped the radius of the search using the green circle:

The first query

The green circle denotes the results. This allows me to formulate three new queries, all three on the edge of the current zone (but inside it):

Second round of queries

You will notice that the first query is fully covered by the second. This allows you to get the entirety of results in an area with as little overlap as possible, and to efficiently sort them by ID (so you know you do not have duplicated).

Caveat: a 50km radius (max) will take 1 query. A 95km radius takes four. A 140km radius takes 13. It quickly ramps up - so if I were you, I'd cache results somewhere.

The id return field is guaranteed unique - the reference is bound to your API key. The difference? The reference allows you to fire a Place Details request to get updated info on a place (some info here).

Hope this helped clear a few things up.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top