2014-04-15 50 views
2

我的應用程序需要找到用戶的當前位置,我已經完成了。然後它需要找到當前用戶位置附近的其他用戶。我爲此使用了Parse。到目前爲止,這是我必須得到用戶的當前位置,它的工作至今。我不明白如何找到當前用戶位置附近的其他用戶。有人可以幫我嗎?我真的很感激它。如何使用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; 
     } 
    }]; 

回答

3

從解析文檔:

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

相關問題