我允许用户设置一个位置,然后创建一个区域并监控用户是否退出或进入了该区域。我还不断监控用户与所选位置的距离。区域监控被调用,距离被正确更新,但从不调用进入和退出。这表明我要去 30 米,但我走得更远,结果相同。
-(void)setPlugLocation:(CLLocation *)plugLocation{
if (!_plugLocation) {
_plugLocation=plugLocation;
if(!regionManager) regionManager = [[CLLocationManager alloc] init];
[regionManager setDelegate:self];
CLLocationCoordinate2D plug2D;
plug2D.latitude=plugLocation.coordinate.latitude;
plug2D.longitude=plugLocation.coordinate.longitude;
CLRegion *plugHome = [[CLRegion alloc]
initCircularRegionWithCenter:plug2D
radius:20
identifier:@"Your Plug"];
[regionManager startMonitoringForRegion:plugHome desiredAccuracy:kCLLocationAccuracyBest];
}
}
debug output:
2012-05-25 21:28:29.921 TestLocation[4412:707] locationManager didUpdateToLocation
2012-05-25 21:28:29.929 TestLocation[4412:707] Distance from plug=0.000000
2012-05-25 21:28:30.700 TestLocation[4412:707] locationManager didUpdateToLocation
2012-05-25 21:28:30.704 TestLocation[4412:707] Distance from plug=9.897339
2012-05-25 21:28:33.106 TestLocation[4412:707] Distance from plug=15.923317
2012-05-25 21:28:34.783 TestLocation[4412:707] region monitoring started
(identifier Your Plug) <+47.61713686,-122.28694184> radius 20.00m
2012-05-25 21:28:34.784 TestLocation[4412:707] region monitoring started
(identifier Your Plug) <+47.61713686,-122.28694184> radius 20.00m
2012-05-25 21:28:34.788 TestLocation[4412:707] Distance from plug=19.705339
2012-05-25 21:28:56.894 TestLocation[4412:707] Distance from plug=12.808387
2012-05-25 21:28:57.894 TestLocation[4412:707] Distance from plug=12.808387
2012-05-25 21:29:05.893 TestLocation[4412:707] Distance from plug=12.808387
2012-05-25 21:29:19.890 TestLocation[4412:707] Distance from plug=12.808387
2012-05-25 21:30:02.892 TestLocation[4412:707] Distance from plug=14.614380
2012-05-25 21:30:32.893 TestLocation[4412:707] Distance from plug=14.614380
2012-05-25 21:30:52.891 TestLocation[4412:707] Distance from plug=15.352976
2012-05-25 21:32:41.898 TestLocation[4412:707] Distance from plug=7.644082
2012-05-25 21:32:43.891 TestLocation[4412:707] Distance from plug=12.354503
2012-05-25 21:32:49.068 TestLocation[4412:707] Distance from plug=15.757565
2012-05-25 21:32:52.984 TestLocation[4412:707] Distance from plug=21.126129
2012-05-25 21:32:56.880 TestLocation[4412:707] Distance from plug=26.952410
2012-05-25 21:33:04.925 TestLocation[4412:707] Distance from plug=31.824801