CLLocation区域监控已启动,但在iPhone上没有调用didExitRegion

时间:2012-05-26 04:52:00

标签: ios cllocationmanager

我允许用户设置位置,然后创建一个区域并监控用户是退出还是进入该区域。我还会不断监控用户与所选位置的距离。 调用区域监视,并正确更新距离,但从不调用进入和退出。这显示我要走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

1 个答案:

答案 0 :(得分:0)

您是否正在实施正确的区域监控回调方法?

-didEnterRegion
-didExitRegion

关于区域监测的一些信息。它并不像你想象的那么精确。将添加最小区域大小。最小尺寸为100M。所以你在100M以下添加的任何东西都会被提升到100M。

看起来你的输出中有位置更新,所以我猜你只需要实现CLLocationManagerDelegate方法来处理区域监控。您还可以进行监控以确保正确添加区域。这可能是一个错误导致没有回调。

-monitoringDidFailForRegion

希望这有帮助。