我的应用程序需要找到用户的当前位置,我已经做到了。然后它需要找到当前用户位置附近的其他用户。我正在为此使用 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 的距离(从最近到最远)排序的对象数组。
关于ios - 如何使用 Parse 找到当前用户位置附近的用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23093557/