我需要使用我的应用获取最近的 15 个用户的列表。当前用户的当前位置是这样存储的:
PFGeoPoint *currentLocation = [PFGeoPoint geoPointWithLocation:newLocation];
PFUser *currentUser = [PFUser currentUser];
[currentUser setObject:currentLocation forKey:@"location"];
[currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error)
{
NSLog(@"Saved Users Location");
}
}];
现在我想通过 PFQuery 检索附近的用户,如下所示:
- (NSArray *)findUsersNearby:(CLLocation *)location
{
PFGeoPoint *currentLocation = [PFGeoPoint geoPointWithLocation:location];
PFQuery *locationQuery = [PFQuery queryWithClassName:@"User"];
[locationQuery whereKey:@"location" nearGeoPoint:currentLocation withinKilometers:1.0];
locationQuery.limit = 15;
NSArray *nearbyUsers = [locationQuery findObjects];
return nearbyUsers;
}
不幸的是,它不起作用。我的数组似乎没有条目。有人可以为我澄清一下,如何以正确的方式使用查询?
干杯,大卫
(也发布在:https ://www.parse.com/questions/pfquery-to-retrieve-users-nearby )