Reputation: 1204
I've taken a picture at the keizersgracht
in Amsterdam
. I'm building a feature that, in the case that there is a strict match between the location of the photo and Foursquare venue, I include a location to where the photo was taken. Otherwise, I wish the result to be nil
.
Documentation to the Foursquare API call I'm making can be found here: https://developer.foursquare.com/docs/venues/search
Since I don't know what kind of venue the picture is taken at, I can't add a query
parameter, which excludes intent=match
from the options. As a workaround, I've chosen to use intent=checkin
and add almost all categoryId's
to the request.
My request now looks like this:
//latitude & longitude are taken as parameters to the method
NSString *clientId = @"redacted";
NSString *clientSecret = @"redacted";
NSString *version =@"20140806";
NSString *limit = @"1";
NSString *radius = @"1";
NSString *categoryId = @"4d4b7104d754a06370d81259,4bf58dd8d48988d1b4941735,4bf58dd8d48988d1b2941735,4bf58dd8d48988d1a8941735,4bf58dd8d48988d1ad941735,4d4b7105d754a06373d81259,4d4b7105d754a06374d81259,4d4b7105d754a06376d81259,4d4b7105d754a06377d81259,4d4b7105d754a06375d81259,4e67e38e036454776db1fb3a,4d4b7105d754a06378d81259,4d4b7105d754a06379d81259"; //almost all the cat id's
NSDictionary *venueResponse = [self getDataFrom:[NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/search?client_id=%@&client_secret=%@&v=%@&ll=%@,%@&m=foursquare&limit=%@&radius=%@&intent=checkin&categoryId=%@", clientId, clientSecret, version, lat, lng, limit, radius, categoryId]];
NSLog(@"%@",venueResponse);
The method getDataFrom
is about making a simple GET request.
However, when I'm passing a location in the center of Amsterdam, I get out-of radius results, like this one: (snippet)
cc = NL;
city = Amsterdam;
country = Netherlands;
distance = 24;
formattedAddress = (
Amsterdam,
Netherlands
);
This is weird, since I specifically added a radius of 1.
What is it that might cause this and what can I do about it?
Upvotes: 2
Views: 895
Reputation: 98
I'd recommend ditching the radius parameter. Your device has a location. Instead of constructing a request with such a small radius (it is very unlikely that your iPhone is going to have the accuracy of 1 meter in it's location) and so many categories, you could ask for likely nearby locations (which the intent=checkin does) and simply enumerate over the returned data to find the place that is the shortest distance away from your device's location (as @Acey mentions). You can calculate this yourself using the API provided in Core Location, or by using the distance returned on each compact venue. If you don't use a radius parameter, then you aren't required to include categoryIds or a query. (Also, because the accuracy of location on an iPhone can vary you will definitely have some cases to solve!) :)
Further, if the app is only for photos at one particular category of places (say, coffee shops) then requesting that categoryId in your GET request makes sense. Unless I am misunderstanding, it seems like you are including categoryIds just because you think you need to include a radius parameter, which I don't think is necessary.
If you want the "best" match for a particular user, you will need to allow the user to authenticate with their Foursquare account. Foursquare will then return the "best" match for a venue that is personalized to that user probably based on, at least, their checkin history.
Also, if you are persisting this data in your app and don't want to offer authentication to Foursquare, you could create your own algorithms on the device using the user's accumulated data in order to help decide what location a user is at when they take future photos.
Good luck building the app. Seems like a neat idea with some good challenges to think through.
Upvotes: 1
Reputation: 8116
The distance value on the result is the distance from the center of that location. In the case of Amsterdam, the location is large enough that part of it is located within 1 mile of your location. Think of overlapping circles. The distance between the centers may be larger than 1, but the distance from your circle to any part of the location is, well, 0 actually.
I would guess the result set you get back contains multiple places. I would go through the results and choose the venue with the shortest distance, that should give you the most accurate venue.
Upvotes: 1