【问题标题】:How can I find users near the current user's location using Parse?如何使用 Parse 找到当前用户位置附近的用户?
【发布时间】:2014-04-15 20:12:03
【问题描述】:

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

【问题讨论】:

    标签: ios objective-c geolocation parse-platform geocode


    【解决方案1】:

    来自解析文档:

    // 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-02
      • 1970-01-01
      • 2014-04-03
      • 2016-04-24
      相关资源
      最近更新 更多