首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iPhone区域监控-区域没有添加?

iPhone区域监控-区域没有添加?
EN

Stack Overflow用户
提问于 2010-12-21 11:31:33
回答 1查看 1K关注 0票数 1

我在试着建立区域监控系统。看起来很简单;但是当我检查我所监视的区域的数量时,计数总是为0。

代码:

代码语言:javascript
运行
复制
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 xxxxx8112:307

怎么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-02 08:55:59

我的印象是

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

由于这些问题和区域监测不太准确的事实,我放弃了使用该功能的想法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4498760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档