can't find anything using smquery within milesof

8 views
Skip to first unread message

izon ho

unread,
Feb 13, 2013, 8:26:54 AM2/13/13
to stac...@googlegroups.com
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.
- (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



Reply all
Reply to author
Forward
0 new messages