我的应用程序需要找到用户的当前位置,我已经完成了。然后它需要找到当前用户位置附近的其他用户。我正在为此使用 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];
placeObjects 将是按距 userGeoPoint 的距离(从最近到最远)排序的对象数组。
https://www.parse.com/docs/ios_guide#geo-query/iOS https://www.parse.com/docs/ios_guide#geo-query/iOS
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)