I am run in my application for finding a current location but first time return right lat long with there dependent locality but when they didUpdateLocations that time goes to didFailWithError and return Domain=kCLErrorDomain Code=0 "(null)". I have try diffrent diffrent solution like
- Reset Content and Settings
- In Xcode,Product -> Scheme -> Edit Scheme,then cancel the "Allow Location Simulator"and To the iOS Simulator and reset Content and Setting and Again to the Xcode,repeat the first step.and To the iOS Simulator and reset.
but none of that work
my code for this is here:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations{
NSLog(@"didUpdateToLocation: %@", [locations lastObject]);
CLLocation *currentLocation = [locations lastObject];
if (currentLocation != nil)
{
self.lblLongitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.longitude];
self.lblLatitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.latitude];
}
NSLog(@"Resolving the Address");
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
NSString *geoMapItem = placemark.description;
NSRange start = [geoMapItem rangeOfString:@"dependentLocality"];
NSRange end = [geoMapItem rangeOfString:@")" options:NSCaseInsensitiveSearch range:NSMakeRange(start.location, 1000)];
NSString *dataString = [geoMapItem substringWithRange:NSMakeRange(start.location, end.location - start.location + end.length)];
dataString = [dataString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
dataString = [dataString stringByReplacingOccurrencesOfString:@" " withString:@""];
dataString = [dataString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
start = [dataString rangeOfString:@"("];
end = [dataString rangeOfString:@")"];
NSLog(@"datastring===>%@",dataString);
lblAddress.text = [NSString stringWithFormat:@"%@ \n%@ %@\n%@\n%@",
dataString,
placemark.postalCode, placemark.locality,
placemark.administrativeArea,
placemark.country];
} else
{
NSLog(@"%@", error.debugDescription);
}
} ];}
after update location first time goes to error block
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
NSLog(@"didFailWithError%@",error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];}
and get this error didFailWithErrorError Domain=kCLErrorDomain Code=0 "(null)"