0

我正在尝试查找位置,但我得到一个空数组返回。它成功了,但没有得到任何回报。在对象浏览器中,我可以说“位置”中有值。我使用当前位置保存了多个位置。这行得通吗?

- (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
4

1 回答 1

2

我是 StackMob 的一名 iOS 开发人员。

我们的 SDK 现在支持在 Core Data 中保存和查询地理位置。有关更多信息,请查看此博客文章:https ://blog.stackmob.com/2013/02/stackmob-ios-sdk-v1-3-0-release/

于 2013-02-15T01:06:38.123 回答