繁体   English   中英

如何使用Parse查找当前用户位置附近的用户?

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

我的应用程序需要找到用户的当前位置,这已经完成。 然后,它需要查找当前用户位置附近的其他用户。 我为此使用解析。 到目前为止,这是我必须获取用户的当前位置的信息,并且到目前为止,它仍在工作。我不了解如何在当前用户的位置附近找到另一个用户。 有人可以帮我吗? 我真的很感激。

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

从解析文档中:

// 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将是一个对象数组,该数组按与userGeoPoint的距离(最近到最远)排序。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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