【问题标题】:How to know I'm leaving from a location如何知道我要从某个位置离开
【发布时间】:2013-05-15 07:39:01
【问题描述】:

我在 ios 6 中使用 Core Location。 我一直在寻找这个,但可以找到合适的解决方案

我的问题是: - 我怎么知道我是否要离开 X 点(在我越过它之后)?

【问题讨论】:

  • 经纬度变化时可以查到。

标签: iphone ios ios6 geolocation core-location


【解决方案1】:
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

CLLocation *curPos = locationManager.location;

latitude = [[NSNumber numberWithDouble:curPos.coordinate.latitude] floatValue];

longitude = [[NSNumber numberWithDouble:curPos.coordinate.longitude] floatValue];

if (ABS( latitude - XlocationLAT)>0.1 ||ABS( longitude - XlocationLON)>0.1 ) {
    NSLog(@"He is out");
}
}

【讨论】:

    【解决方案2】:

    您可以使用 Geo Fence API

    CLLocationManager

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:CLLocationCoordinate2DMake(0, 0) radius:100.0 identifier:@"Identifier"];
    [locationManager startMonitoringForRegion:region];
    

    然后跟踪委托方法的变化:

    - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {}
    - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {}
    

    并且不要忘记启用后台模式 UIBackgroundModes。

    【讨论】:

    • UIBackgroundModes 不是必需的。它确实会消耗大量电池寿命。如果您可以容忍精度,建议使用显着的位置变化。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    相关资源
    最近更新 更多