简体   繁体   中英

How can I find users near the current user's location using Parse?

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;
        }
    }];

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM