foursquare

Searching closest venues using ll and radius not working properly


I know there are a lot of questions about this issue, but I've reached a point where I can't really do anything else but to ask if somebody else has a solution for this issue...

Using the Foursquare api explorer to test out my query I can't seem to obtain an accurate or even good fit for the data I need to obtain.

It is quite simple. I need to obtain the closest venue from a set of coordinates. I don't mind not having results if nothing is found near by.

So, reading the API documentation (https://developer.foursquare.com/docs/venues/venues) I conclude that I need a search and not an explore because I don't want sugestions of recommended venues (and the results when I tested it proved that it wasn't what I was expecting).

So, using search api I want to find places (the place, but places would do...) close to these coordinates

ll=37.424782,-122.162989

considering that I want places close by, I add

radius=51

and I don't really want many results

limit=2

from the documentation I see that radius is

Only valid for requests with intent=browse, or requests with intent=checkin and categoryId or query

so, I use

intent=browse

which concludes my query to: venues/search?intent=browse&ll=37.424782,-122.162989&radius=51&limit=2

Query Result: https://developer.foursquare.com/docs/explore#req=venues/search%3Fintent%3Dbrowse%26ll%3D37.424782,-122.162989%26radius%3D51%26limit%3D2

Here we can see that the first result is straight outside of the radius ... distance: 135 the second result however is cool ... distance: 50

What am I doing wrong to get these results? If I increase the limit all I get is more results that are also outside the radius, I could iterate through them and find the one with the smallest distance... but I have no guarantee that the closest result will be on the top X that I limit, even If I had that guarantee, it would be a tiresome solution to an apparently simple question...

Thanks for the help... Marc


EDIT:


I managed to make have the query perform as I intended ... But I had to add all of the parent categories from:

https://developer.foursquare.com/categorytree

categoryId=
4d4b7104d754a06370d81259,  Arts & Entertainment
4d4b7105d754a06372d81259,  College & University
4d4b7105d754a06373d81259,  Event
4d4b7105d754a06374d81259,  Food
4d4b7105d754a06376d81259,  Nightlife Spot
4d4b7105d754a06377d81259,  Outdoors & Recreation
4d4b7105d754a06375d81259,  Professional & Other Places
4e67e38e036454776db1fb3a,  Residence
4d4b7105d754a06378d81259,  Shop & Service
4d4b7105d754a06379d81259   Travel & Transport

making my query into: venues/search?

intent=checkin&ll=37.424782,-122.162989&radius=60&categoryId=4d4b7104d754a06370d81259,4d4b7105d754a06372d81259,4d4b7105d754a06373d81259,4d4b7105d754a06374d81259,4d4b7105d754a06376d81259,4d4b7105d754a06377d81259,4d4b7105d754a06375d81259,4e67e38e036454776db1fb3a,4d4b7105d754a06378d81259,4d4b7105d754a06379d81259

Query Result: https://developer.foursquare.com/docs/explore#req=venues/search%3Fintent%3Dcheckin%26ll%3D37.424782,-122.162989%26radius%3D60%26categoryId%3D4d4b7104d754a06370d81259,4d4b7105d754a06372d81259,4d4b7105d754a06373d81259,4d4b7105d754a06374d81259,4d4b7105d754a06376d81259,4d4b7105d754a06377d81259,4d4b7105d754a06375d81259,4e67e38e036454776db1fb3a,4d4b7105d754a06378d81259,4d4b7105d754a06379d81259

It still has results outside of my radius still ... but it's an acceptable error margin ... it is weird however.


Solution

  • I managed to make have the query perform as I intended ... But I had to add all of the parent categories from:

    https://developer.foursquare.com/categorytree

    categoryId= 4d4b7104d754a06370d81259, Arts & Entertainment 4d4b7105d754a06372d81259, College & University 4d4b7105d754a06373d81259, Event 4d4b7105d754a06374d81259, Food 4d4b7105d754a06376d81259, Nightlife Spot 4d4b7105d754a06377d81259, Outdoors & Recreation 4d4b7105d754a06375d81259, Professional & Other Places 4e67e38e036454776db1fb3a, Residence 4d4b7105d754a06378d81259, Shop & Service 4d4b7105d754a06379d81259 Travel & Transport making my query into: venues/search?

    intent=checkin&ll=37.424782,-122.162989&radius=60&categoryId=4d4b7104d754a06370d81259,4d4b7105d754a06372d81259,4d4b7105d754a06373d81259,4d4b7105d754a06374d81259,4d4b7105d754a06376d81259,4d4b7105d754a06377d81259,4d4b7105d754a06375d81259,4e67e38e036454776db1fb3a,4d4b7105d754a06378d81259,4d4b7105d754a06379d81259

    Query Result: https://developer.foursquare.com/docs/explore#req=venues/search%3Fintent%3Dcheckin%26ll%3D37.424782,-122.162989%26radius%3D60%26categoryId%3D4d4b7104d754a06370d81259,4d4b7105d754a06372d81259,4d4b7105d754a06373d81259,4d4b7105d754a06374d81259,4d4b7105d754a06376d81259,4d4b7105d754a06377d81259,4d4b7105d754a06375d81259,4e67e38e036454776db1fb3a,4d4b7105d754a06378d81259,4d4b7105d754a06379d81259

    It still has results outside of my radius still ... but it's an acceptable error margin ... it is weird however.