【问题标题】:iPhone region monitoring - regions not added?iPhone 区域监控 - 未添加区域?
【发布时间】:2010-12-21 11:31:33
【问题描述】:

我正在尝试设置区域监控。看起来很简单;但是当我检查我监控的区域数时,计数始终为 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

怎么了????

【问题讨论】:

    标签: ios4 monitoring cllocationmanager region locationmanager


    【解决方案1】:

    我的印象是

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

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

    【讨论】:

    • 我在 iOS5 上看到 regionMonitoring 的类似不可靠性。你在 iOS5 上运气好吗?
    猜你喜欢
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 2014-01-13
    • 2018-08-04
    • 2015-07-17
    • 2015-03-23
    相关资源
    最近更新 更多