2012-03-19 50 views
1

我想通過CLlocationManager對象在Xcode中使用coreloaction框架獲取當前位置名稱。當我在我的iPod touch上測試我的應用程序時,CLlocationManager爲某些地方提供了值,但在許多地方返回[null]。我該如何糾正這個問題?幫我跟隨編碼。CLLocationManager爲Xcode中的locality返回null

-(void)viewDidLoad 
{ 
     self.locationManager = [[CLLocationManager alloc] init] ; 
     self.locationManager.delegate = self; 
     self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers; 
     [self.locationManager startUpdatingLocation];  
} 

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    CLGeocoder *geoCoder = [[CLGeocoder alloc]init]; 

    [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) 
    { 
     if(error) 
     { 
      NSLog(@"error:%@",[error localizedDescription ]); 
      NSLog(@"Check your inetconnection"); 
     } 
     _placedetail=nil; 
     self.placedetail=[placemarks objectAtIndex:0]; 

     self.Label.text=self.placedetail.locality; 
    }]; 
    [manager stopUpdatingLocation];//for stop process update 
} 

回答

1

這個問題很久以前。但是我在這裏添加我的解決方案以備將來參考

我有同樣的問題。我認爲它的發生是由於地圖在一些小城市尚未更新。或地方衝突。爲了避免這種崩潰嘗試錯誤處理給予子位置。

例如:如果沒有可用的本地區,請選擇更大的選項。