joshtronic / php-googleplaces

PHP Wrapper for the Google Places API
MIT License
85 stars 38 forks source link

Pull more than 60 results with multiple small radius searches #5

Closed joshtronic closed 9 years ago

joshtronic commented 10 years ago

originally posted by @bristweb on issue #4 :

One other thing on a similar vein, but not really specific to this project. Google definitely limits a particular search to 60 results. I had hoped that I could just spend more of my quota in order to get an exhaustive dataset, but apparently that isn't possible without a bunch of legwork. The only way I can think of to accomplish this is to do a whole ton of small radius searches - resulting in something like this: http://cdn2.techworld.com/cmsdata/slideshow/3310742/09_crop_circles_thumb555.jpg

jonathanstanley commented 10 years ago

Thanks Josh. Hopefully I'll have this in a pull request for you in a couple weeks. Though my scheduling never seems to go like I hope it will :)

joshtronic commented 10 years ago

Heh, I know how that goes. Eager to see what you come up with, but I'll be patient :) Cheers!

jonathanstanley commented 10 years ago

Possibly stating the obvious, but here's the sort of improvement this gives. Google Maps / Google Places API currently limits us to 60 results for a search. The subradius I built gives us the ability to get more data.

If we assume a radius of 40,000m and a subradius of 20,000m: divisions = 40,000/20,000 = 2 base starting points = (divisions+1)^2 = 9 max queries = (base starting points) * 3 = 27 max results = (max queries * 20) = 540

So, for that example, the maximum possible results would be 540 instead of 60. In my tests, it took 30-60 seconds to complete a query yielding 484 results. YMMV

If we were to perform a query with a radius of 40,000 and subradius of 10,000: 40000/10000 = 4. (4+1)^2 = 25. 25_3 = 75. 75_20 = up to 1500 results !

Max results are as follows depending on the subradius' ratio to the full radius: 1/2 = 540 1/4 = 1500 1/6 = 2940 1/8 = 4860 1/10 = 7260

jonathanstanley commented 10 years ago

Some more info for anyone interested in pulling more results from Google's API.

Here are some real world results (YMMV): 40000m radius w/ 20000m subradius: 25 queries, 484 results, 1 minute runtime 40000m radius w/ 10000m subradius: 54 queries, 917 results, 2 minute runtime 39996m radius w/ 6666m subradius: 94 queries, 1546 results, 3 minute runtime 40000m radius w/ 5000m subradus: 152 queries, 2227 results, 4.5 minute runtime

Also, it is good to keep in mind that because google limits to 60 results for a given search, results are biased towards geographically isolated matches. For example, a search over a shopping mall will still only yield 60 results. No matter how small the radius, all those businesses sharing the same address are limited to 60 results.

joshtronic commented 9 years ago

Been sitting around over a year, gonna close it out. Re-open if ya need to!

highoncarbs commented 5 years ago

Hey ! Thanks for the breakdown , But I'd like to know if this method still works ?