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