我正在尝试查找位置,但我得到一个空数组返回。它成功了,但没有得到任何回报。在对象浏览器中,我可以说“位置”中有值。我使用当前位置保存了多个位置。这行得通吗?
- (void)geoQuery
{
MKCoordinateRegion region;
region = MKCoordinateRegionMakeWithDistance(locationController.locationManager.location.coordinate, 5000, 5000);
[self.mapView setRegion:region animated:YES];
SMQuery *query = [[SMQuery alloc] initWithSchema:@"event"];
[query where:@"location" isWithin:10 kilometersOf:locationController.locationManager.location.coordinate];
[[[SMClient defaultClient] dataStore] performQuery:query onSuccess:^(NSArray *results) {
NSLog(@"%@", results);
} onFailure:^(NSError *error) {
NSLog(@"can't find any");
}];
}
这些是创建新事件的方法,包括地理位置数据:
- (void)onCreate:(QButtonElement *)buttonElement
{
EventInfo *eventInfo = [[EventInfo alloc] init];
Event *event = [[Event alloc] initIntoManagedObjectContext:self.managedObjectContext];
[event setValue:[event assignObjectId] forKey:[event primaryKeyField]];
[event setValue:eventInfo.title forKey:@"title"];
NSDecimalNumber *latDecimal = [[NSDecimalNumber alloc] initWithDouble:mapViewController.locationManager.location.coordinate.latitude];
NSDecimalNumber *lonDecimal = [[NSDecimalNumber alloc] initWithDouble:mapViewController.locationManager.location.coordinate.longitude];
[event setValue:latDecimal forKey:@"lat"];
[event setValue:lonDecimal forKey:@"lon"];
[self.managedObjectContext saveOnSuccess:^{
[self.navigationController popViewControllerAnimated:YES];
} onFailure:^(NSError *error) {
[self.managedObjectContext deleteObject:event];
}];
}
和数据模型:
@interface Event : NSManagedObject
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSNumber * lat;
@property (nonatomic, retain) NSNumber * lon;
@end