我有要求,我必须为 CLLocation
设置 radius。我在 viewDidLoad
方法中编写代码如下:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDistanceFilter:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
CLLocationDegrees latitude = 37.33036720;
CLLocationDegrees longitude = -122.02923067;
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(latitude, longitude);
CLLocationDistance radius = 100.0;
CLRegion *region = [[CLRegion alloc]initCircularRegionWithCenter:center radius:radius identifier:@"Apple"];
[locationManager startMonitoringForRegion:region];
}
委托(delegate)方法如下:
-(void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region{
NSLog(@"didStartMonitoringForRegion %@", region);
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSLog(@"didEnterRegion %@", region);
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
NSLog(@"didExitRegion %@", region);
}
我从位置日志中获取了一些静态位置。但是这些方法未调用。
最佳答案
可能是您的区域半径太小,您不可能获得准确的接送服务。尝试将其从半米扩展。
您也可以尝试设置精度,但我几乎可以肯定半径是您的主要问题。
或者可能是
在设备上测试区域监控代码时,请注意区域事件可能不会在区域边界被跨越后立即发生。为防止虚假通知,iOS
在满足特定阈值条件之前不会发送区域通知。具体来说,用户的位置必须越过区域边界并离开该边界最小距离,并在报告通知之前保持该最小距离至少 20-30 秒。
具体的阈值距离由硬件和当前可用的定位技术决定。例如,如果 Wi-Fi 被禁用,区域监控的准确性就会大大降低。但是,出于测试目的,您可以假设最小距离约为 200 米。
关于iphone - 未调用区域委托(delegate)方法的 CLLocationManger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16565525/