0

我正在使用带有 ios 6 的核心位置。我一直在寻找这个,但可以找到一个合适的解决方案

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

4

2 回答 2

0
- (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");
}
}
于 2013-05-15T07:48:26.950 回答
0

你可以使用地理围栏 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。

于 2013-05-15T08:49:18.137 回答