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

时光怂恿深爱的人放手 提交于 2019-12-11 03:34:37

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/23093557/how-can-i-find-users-near-the-current-users-location-using-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!