iOS - CLGeocoder without internet connection
clgeocoder, ios
Solution
Geocoding isn't the same as geolocation. The GPS is used to determine your geolocation and the result of that is a latitude/longitude position. Geocoding is the process of converting between that geolocation and the corresponding address details.
While geolocation doesn't require an Internet connection, geocoding does because it's a lookup on an Apple database to find the address for the geolocation.
Problem
I am using `CLGeocoder` to locate adresses on a map and calculate the user's distance in comparison to a whole bunch of adresses. Here is the part of the code that uses `CLGeocoder`: ``` CLGeocoder *geocoder = [[CLGeocoder alloc] init]; __block float distance; __block CLLocation *location; [geocoder geocodeAddressString:adresseFinal completionHandler:^(NSArray *placemarks, NSError *error) { if ([placemarks count] > 0) { CLPlacemark *placemark = [placemarks objectAtIndex:0]; location = placemark.location; CLLocationCoordinate2D coordinate = location.coordinate; distance = [userLocation distanceFromLocation:location]; [distanceArray addObject:[NSString stringWithFormat:@"%f", distance]]; MKPointAnnotation *point = [[MKPointAnnotation alloc] init]; point.coordinate = coordinate; point.title = tableNoms[i]; NSMutableArray *coords = [[NSMutableArray alloc] init]; [coords addObject:location]; [coords addObject:userLocation]; [self.mapView addAnnotation:point]; } dispatch_group_leave(group); }]; ``` But when I try and use it without internet connection, I get the following error: Could not determine current country code: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo=0x7877f930 {NSErrorFailingURLStringKey=http://gsp1.apple.com/pep/gcc, _kCFStreamErrorCodeKey=8, NSErrorFailingURLKey=http://gsp1.apple.com/pep/gcc, NSLocalizedDescription=The Internet connection appears to be offline., _kCFStreamErrorDomainKey=12, NSUnderlyingError=0x7877ed30 "The Internet connection appears to be offline."} I thought I was able to use localisation without internet (using GPS?)? Do I have to change something in my code in order to be able to use it? Thanks a lot !