Madhubalan K
Madhubalan K

Reputation: 357

CLLocationManager return null for locality in Xcode

I am trying get current location name using coreloaction framework in Xcode through CLlocationManager object. When i am testing my app on my iPod touch CLlocationManager give value for some places but return [null] for many places. how can I rectify this problem? help me following is coding.

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

Upvotes: 1

Views: 444

Answers (1)

Im Batman
Im Batman

Reputation: 1876

This question is long time ago. but ill add my solution here for future reference.

I had the same problem. i think its happening due to maps are not updated yet in for some small cities. or locality conflict. to avoid this crash try error handling with giving sub locality.

Example : if locality not available go with administrative area like bigger option.

Upvotes: 1

Related Questions