【问题标题】:IOS 9 issue : CLGeocoder Network error code 2IOS 9 问题:CLGeocoder 网络错误代码 2
【发布时间】:2015-12-11 19:04:18
【问题描述】:
CLLocation *location =[[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
    NSLog(@"Finding address");
    if (error) {
        NSLog(@"Error %@", error.description);
    } else {
        NSLog(@"%@",placemarks[0]);
    }
}]; }

enum CLError : Int {
        case LocationUnknown
        case Denied
        case Network
        case HeadingFailure
        case RegionMonitoringDenied
        case RegionMonitoringFailure
        case RegionMonitoringSetupDelayed
        case RegionMonitoringResponseDelayed
        case GeocodeFoundNoResult
        case GeocodeFoundPartialResult
        case GeocodeCanceled
        case DeferredFailed
        case DeferredNotUpdatingLocation
        case DeferredAccuracyTooLow
        case DeferredDistanceFiltered
        case DeferredCanceled
        case RangingUnavailable
        case RangingFailure
    }

这里我在 IOS 9 设备中遇到了一个错误(在模拟器中它运行良好 ;-))

地理编码期间出现错误:错误域=kCLErrorDomain Code=2 "The 操作无法完成。 (kCLErrorDomain 错误 2.)"

【问题讨论】:

标签: ios ios8 cllocationmanager ios9 geocode


【解决方案1】:

docs 表示“您每分钟不应发送超过一个地理编码请求”。

kCLErrorNetwork 网络不可用或发生网络错误。

实际上,代码在IOS8IOS7 中运行良好。它只在IOS 9. 中提供Error

它的工作完美。

CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
        [geoCoder cancelGeocode];
        [geoCoder reverseGeocodeLocation:locationManager.location
                       completionHandler:^(NSArray *placemarks, NSError *error)
        {
            NSLog(@"Error is %@",error.localizedDescription);
            for (CLPlacemark *placemark in placemarks) {
                NSLog(@"%@",placemark.ISOcountryCode);
            }
        }];

O/p:

  • 错误为(空)

  • 美国

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 2012-06-28
    • 2012-12-03
    • 2015-12-09
    相关资源
    最近更新 更多