1

我正在尝试设置区域监控。看起来很简单;但是当我检查我监控的区域数时,计数始终为 0。

代码:

if ([CLLocationManager regionMonitoringAvailable] &&
    [CLLocationManager regionMonitoringEnabled] ) {

    CLLocationCoordinate2D coordinate;
    double radius;

    for(Item *item in ad.proxiArray) {

        radius = [item.distance floatValue];

        coordinate= CLLocationCoordinate2DMake([item.latitude doubleValue],
                                                [item.longitude doubleValue]);
        CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:coordinate radius:radius identifier:item.place];

        NSLog(@"Adding: %@", region);

        [self.locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyNearestTenMeters];

        [region release];
    }   
    NSLog(@"region count %i",[[self.locationManager monitoredRegions] count]);
    for (CLRegion *re in [self.locationManager monitoredRegions]) {
        NSLog(@"Monitoring: %@", re);
    }
} else {
    NSLog(@"Region monitoring unavailable");
}

运行时,NSLog 会显示我实际上正在添加所有项目(大约 10 个)。但是在循环结束时,如上所述:

2010-12-21 12:14:38.172 xxxxxx[8112:307] 区域计数 0

怎么了????

4

1 回答 1

1

我的印象是

  • CLLocationManager 本身不是线程安全的。区域监控和位置监控会干扰,有时可能会导致阻塞(根据我的观察,必须有某种超时,因为程序在超过 30 秒后继续工作)
  • 区域将异步添加,因此添加完成后直接检查区域数量可能会导致错误结果。
  • 实际添加要监控的区域时,精度很差(几公里的分辨率)

由于这些问题以及区域监控不是很准确的事实,我放弃了使用该功能的想法。

于 2011-01-02T08:55:59.957 回答