[英]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的距離(最近到最遠)排序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.