问题
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