【问题标题】:CLLocationManger for Region Delegate methods not Invoked未调用区域委托方法的 CLLocationManger
【发布时间】:2013-05-15 12:53:09
【问题描述】:

我有要求,我必须为CLLocation 设置 半径。我在viewDidLoad 方法中将代码编写为:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];    
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [locationManager setDistanceFilter:kCLLocationAccuracyBest];
    [locationManager startUpdatingLocation];
    CLLocationDegrees latitude = 37.33036720;
    CLLocationDegrees longitude = -122.02923067;
    CLLocationCoordinate2D center = CLLocationCoordinate2DMake(latitude, longitude);
    CLLocationDistance radius = 100.0;
    CLRegion *region = [[CLRegion alloc]initCircularRegionWithCenter:center radius:radius identifier:@"Apple"];
    [locationManager startMonitoringForRegion:region];
}

委托方法如下:

-(void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region{
            NSLog(@"didStartMonitoringForRegion %@", region);    
    }

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region  {
            NSLog(@"didEnterRegion %@", region);    
   }

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region  {
    NSLog(@"didExitRegion %@", region);        
}  

我从位置日志中获取了一些静态位置。但是方法不会被调用

【问题讨论】:

  • 试试retain你的locationManager

标签: iphone ios


【解决方案1】:

可能是您所在的区域半径太小,没有机会获得准确的接送服务。尝试从半米扩大它。

您也可以尝试设置精度,但我几乎可以肯定半径是您的主要问题。

或者可能是

在设备上测试您的区域监控代码时,请注意区域事件可能不会在跨越区域边界后立即发生。为防止虚假通知,iOS 在满足某些阈值条件之前不会发送区域通知。具体来说,用户的位置必须越过区域边界并离开该边界一段最小距离,并在该最小距离上保持至少 20-30 秒,然后才会报告通知。

具体的阈值距离由硬件和当前可用的定位技术决定。例如,如果禁用 Wi-Fi,则区域监控的准确性会大大降低。但是,出于测试目的,您可以假设最短距离约为 200 米。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-08-12
  • 1970-01-01
  • 2015-06-09
  • 2016-07-16
  • 2019-01-04
相关资源
最近更新 更多