我正在尝试找到位置,但我得到一个空数组返回。它成功了,但没有得到任何回报。在对象浏览器中,我可以说“位置”中有值。我使用当前位置保存了几个位置。这有用吗?
- (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
答案 0 :(得分:2)
我是StackMob的iOS开发者。
我们的SDK现在支持在Core Data中保存和查询地理位置。有关详细信息,请查看此博文:https://blog.stackmob.com/2013/02/stackmob-ios-sdk-v1-3-0-release/