2013-05-15 23 views
3

我有要求,我必須設置半徑CLLocation。我寫的代碼在viewDidLoad方法:CLLocationManger區域代理方法未調用

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

我從位置登錄採取了一些靜態位置。但方法是沒有被調用

+0

嘗試'保留'你的'locationManager'。 –

回答

0

可能是你的地區半徑太小,沒有機會你會得到一個準確的皮卡。嘗試從半米擴大。

您也可以嘗試設置精度,但半徑是您的主要問題,我幾乎可以肯定。

,或者可以

當一臺設備上測試你的區域監管碼,實現區域越過邊界後,該區域的事件可能不會立即發生。爲了防止虛假通知,iOS在滿足某些閾值條件之前不會傳遞區域通知。具體而言,用戶的位置必須穿過區域邊界並離開該邊界最小距離,並且在通知被報告之前保持在該最小距離處至少20-30秒。

具體的閾值距離由當前可用的硬件和位置技術確定。例如,如果Wi-Fi已禁用,則區域監控的精確度將大大降低。但是,出於測試目的,您可以假定最小距離大約爲200米。

+0

http://stackoverflow.com/questions/25178981/geo-fencing-didenterregion-and-didexitregion-methods-not-called.Can您可以檢查一下並幫我找出問題 – sabir