ios - 如何使用 Parse 找到当前用户位置附近的用户?

标签 ios objective-c geolocation parse-platform geocode

我的应用程序需要找到用户的当前位置,我已经做到了。然后它需要找到当前用户位置附近的其他用户。我正在为此使用 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

关于ios - 如何使用 Parse 找到当前用户位置附近的用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23093557/

相关文章:

ios - 升级到 Xcode 7 和 iOS 9 后 LaunchScreen.xib 中的图像未显示

iPhone - 设备上的不同默认 boolean 值

ios - 替换两个字符串之间的字符串

database - 是否有可以查询本地城市名称的公共(public)地理定位系统?

javascript - 地理位置自定义更新间隔(30 秒)

ios - 沿世界轴旋转

ios - TableView Controller 的奇怪行为

iphone - 如何在具有从数据库获取内容的 UITableView 中实现按字母顺序排列的节标题

react-native - NativeModule RNCGeolocation 为空

ios - 如何对 Realm List 集合执行实际计数查询?