我尝试运行返回 GeoPint 附近对象的复合查询。我只想检索超过 24 小时的对象。不知何故,我的代码返回了 0 个对象。我只发现 GeoPoints 无法使用 OrQueries。我希望 AND 查询能够工作。感谢您提供如何解决该问题的任何提示或建议。
NSDate *now = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now];
[components setHour:-(24)];
NSDate *queryDate = [calendar dateFromComponents:components];
PFGeoPoint *point = [PFGeoPoint geoPointWithLatitude:self.currentLocation.coordinate.latitude longitude:self.currentLocation.coordinate.longitude];
PFQuery *query = [PFQuery queryWithClassName:@"GeoTag"];
[query whereKey:@"createdAt" greaterThanOrEqualTo:queryDate];
[query whereKey:@"location" nearGeoPoint:point];
// Limit what could be a lot of points.
query.limit = 10;
// Final list of objects
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %ld objects.", objects.count);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(@"%@", object.objectId);
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];