3

我有要求,我必须设置半径CLLocation我在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];
}

委托方法如下:

-(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);        
}  

我从Location Log中获取了一些静态位置。但是没有调用方法。

4

1 回答 1

0

可能是您的区域半径太小,您没有机会获得准确的接送。尝试从半米扩大它。

您也可以尝试设置精度,但我几乎可以肯定半径是您的主要问题。

或者可能

在设备上测试区域监控代码时,要意识到区域事件可能不会在跨越区域边界后立即发生。为防止虚假通知,iOS在满足某些阈值条件之前不发送区域通知。具体来说,用户的位置必须越过区域边界并离开该边界一个最小距离,并在报告通知之前保持该最小距离至少 20-30 秒。

具体的阈值距离由硬件和当前可用的定位技术决定。例如,如果禁用 Wi-Fi,则区域监控的准确性会大大降低。但是,出于测试目的,您可以假设最小距离约为 200 米。

于 2013-05-15T13:03:47.747 回答