can't Find location within milesof using stackmob as backend

孤街醉人 提交于 2019-12-11 17:58:51

问题


I am trying to find the locations, but I am getting a empty array returned. It succeeded, but got nothing back. In the object brower, i can say there are values in the "location". I have saved several locations using my current location. Will this work?

- (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");
    }];
}

These are the method to create new event includes geo location data:

- (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];
    }];
}

and the data model:

@interface Event : NSManagedObject
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSNumber * lat;
@property (nonatomic, retain) NSNumber * lon;
@end

回答1:


I'm an iOS dev at StackMob.

Our SDK now supports saving and querying geo locations in Core Data. For more information check out this blog post: https://blog.stackmob.com/2013/02/stackmob-ios-sdk-v1-3-0-release/



来源:https://stackoverflow.com/questions/14836646/cant-find-location-within-milesof-using-stackmob-as-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!