使用stackmob作为后端无法在数英里内找到位置 [英] can't Find location within milesof using stackmob as backend

查看:80
本文介绍了使用stackmob作为后端无法在数英里内找到位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到位置,但是返回一个空数组.它成功了,但一无所获.在对象浏览器中,我可以说位置"中有值.我使用当前位置保存了几个位置.这样行吗?

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

和数据模型:

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

推荐答案

我是StackMob上的iOS开发人员.

I'm an iOS dev at StackMob.

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

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/

这篇关于使用stackmob作为后端无法在数英里内找到位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆