iPhone 区域监控 - 区域未添加?
我正在尝试设置区域监控。看起来很简单;但是当我检查我监视的区域数量时,计数始终为 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
怎么了???
I'm trying to set up region monitoring. Looks pretty straightforward; but when I check the number of regions I monitor, the count is always 0.
Code:
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");
}
When run, NSLog will show that I am actually adding all items (about 10). But at the end of the loop, as stated above:
2010-12-21 12:14:38.172 xxxxxx[8112:307] region count 0
What's wrong????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的印象是
由于这些问题以及区域监控不太准确,我放弃了使用该功能的想法。
My impression is that
Because of these problems and the fact that region monitoring is not very accurate, I gave up the idea of using that feature.