Question

My app needs to find the user's current location, which I have done. Then it needs to find other users that are near the current user's location. I am using Parse for this. So far this is what I have to get the user's current location and it is working so far.I don't understand how to find the other user near the current user's location though. Can someone please help me out? I'd really appreciate it.

if ([PFUser currentUser] && [PFFacebookUtils isLinkedWithUser:[PFUser currentUser]]) {
    [self updateUserInformation];

    [PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {
        if (!error) {
            NSLog(@"User is currently at %f, %f", geoPoint.latitude, geoPoint.longitude);
            [[PFUser currentUser]  setObject:geoPoint forKey:@"currentLocation"];
            [[PFUser currentUser] saveInBackground];
        } else {
            NSLog(@"%@", error);
            return;
        }
    }];
Was it helpful?

Solution

From the parse docs:

// User's location
PFGeoPoint *userGeoPoint = userObject[@"currentLocation"];
// Create a query for places
PFQuery *query = [PFQuery queryWithClassName:@"_User"];
// Interested in locations near user.
[query whereKey:@"location" nearGeoPoint:userGeoPoint];
// Limit what could be a lot of points.
query.limit = 10;
// Final list of objects
placesObjects = [query findObjects];

placesObjects will be an array of objects ordered by distance (nearest to farthest) from userGeoPoint.

https://www.parse.com/docs/ios_guide#geo-query/iOS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top