2012-03-19 45 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

这个问题很久以前。但是我在这里添加我的解决方案以备将来参考

我有同样的问题。我认为它的发生是由于地图在一些小城市尚未更新。或地方冲突。为了避免这种崩溃尝试错误处理给予子位置。

例如:如果没有可用的本地区,请选择更大的选项。