我想使用监控区域来跟踪用户是否曾访问过地标。 外景经理是在视图控制器初始化在视图控制器的viewDidLoad中一个mapkitiphone CLLocationmanager区域监控回调未触发
沿:
if (self.locationManager == nil)
{
// NSLog(@"creating location manager");
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.distanceFilter = kCLDistanceFilterNone;
}
NSSet* set=[locationManager monitoredRegions];
if ([CLLocationManager regionMonitoringAvailable] && [CLLocationManager regionMonitoringEnabled]) {
NSLog(@"region monitoring okay");
NSLog(@"monitored regions: %@",set);
}
我得到的NSLogs“区域监控好”正确和所有地区。
加入地区都像这样
double metres=20.0;
CLLocationDistance dist=metres;
CLLocationAccuracy acc=1.0;
CLRegion *reg=[[CLRegion alloc] initCircularRegionWithCenter:coordinate radius:dist identifier:landmarkObj.landmarkName];
[locationManager startMonitoringForRegion:reg desiredAccuracy:acc];
完成,但回调都不会触发
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Entered"
message:region.identifier
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Exited"
message:region.identifier
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
NSLog(@"started monitring for region: %@",region);
}
- (void) locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
NSLog(@"%@",error);
}
然而更新的位置,工作正常。
[locationManager startUpdatingLocation];
触发回调didUpdateToLocation预期
更新:使用didUpdatToLocation监视的区域来代替。 仍然有兴趣知道为什么这不起作用,但看起来很少有成功的区域监测
您是否找出了解决此问题的解决方案?我遇到了同样的问题,并且StartStonMonitoringForRegion没有启动。 – Das 2012-08-06 03:15:58
事实证明,区域监控并不能提供我需要的精度。我最终为每个didUpdateToLocation回调进行手动检查。这对我来说是可行的,因为我只跟踪10个区域 – tzl 2012-08-24 06:47:40