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
}