iOS - 没有互联网连接的 CLGeocoder

标签 ios clgeocoder

我正在使用 CLGeocoder 在 map 上定位地址并计算用户与一大堆地址的距离。

这是使用 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);
}];

但是当我尝试在没有互联网连接的情况下使用它时,出现以下错误:

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."}

我认为我可以在没有互联网的情况下使用本地化(使用 GPS?)?

我是否必须更改我的代码才能使用它?

非常感谢!

最佳答案

地理编码与地理定位不同。 GPS 用于确定您的地理位置,其结果是纬度/经度位置。地理编码是在该地理位置和相应的地址详细信息之间进行转换的过程。

虽然地理定位不需要互联网连接,但地理编码需要,因为它是在 Apple 数据库中查找地理定位地址。

关于iOS - 没有互联网连接的 CLGeocoder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28657406/

相关文章:

ios - 如何在swift 3中实现ZCAnimatedLabel的默认效果

ios - 如何实现从ControlCenter中查找?

ios - UIKit Dynamics 添加重力/碰撞/弹跳以重新定位 subview

ios - UIImage imageNamed : name returns nil the second time

ios - Apple 的反向地理编码国家列表

ios - NSOperationQueue 和传递数据

xcode - Swift 2 、 CLGeocoder() 和地标

swift - 使用 CLGeocoder 调用时参数 #1 缺少参数

iphone - iOS5 CLGeocoder