PFQuery *fromRequests = [PFQuery queryWithClassName:@"FriendshipRequest"];
[fromRequests whereKey:@"fromUser" equalTo:[PFUser currentUser]];
PFQuery *toRequests = [PFQuery queryWithClassName:@"FriendshipRequest"];
[toRequests whereKey:@"toUser" equalTo:[PFUser currentUser]];
PFQuery *friendship = [PFQuery orQueryWithSubqueries:@[fromRequests, toRequests]];
[friendship whereKey:@"status" equalTo:@"accepted"];
[friendship includeKey:@"fromUser"];
[friendship includeKey:@"toUser"];
[friendship findObjectsInBackgroundWithBlock:^(NSArray *friendshipObjects, NSError *error) {
if (!error) {
}
}];
这就是我如何获得特定用户的朋友。友谊模型包含以下字段:
并且每个用户都有一个currentLocation
字段。在一个单独的方法中,我从这个friendshiprequest
数组中获取用户。所以,我有一个包含几个PFUser
对象的数组。 (这是当前用户的朋友)
我想要的是获取用户,只使用whereKey: nearGeoPoint:
方法接近当前用户的当前位置。
我怎样才能实现这个目标?
谢谢。答案 0 :(得分:1)
以下内容应该有效:
PFQuery *nearbyUserQuery = [PFUser query];
[nearbyUserQuery whereKey:@"currentLocation" nearGeoPoint:userGeoPoint];
// set some sensible limit here
nearbyUserQuery.limit = 10;
然后在fromRequests
和toRequests
上为其他用户添加额外的约束:
[fromRequests whereKey@:"toUser" matchesQuery:nearbyUserQuery];
[toRequests whereKey@:"fromUser" matchesQuery:nearbyUserQuery];
其余代码可以保持不变。