【问题标题】:CLGeocoder reverse geocoding fails with Error Domain=NSURLErrorDomain Code=-1000 -CLGeocoder 反向地理编码失败,错误域=NSURLErrorDomain 代码=-1000 -
【发布时间】:2014-03-19 16:42:10
【问题描述】:

使用 CLLocation 对象(内容例如纬度 = 48.196169,经度 = 11.620237),我尝试获取当前城市和国家/地区,例如:

if(!geocoder) {
    geocoder = [[CLGeocoder alloc] init];
}

if (geocoder.geocoding) [geocoder cancelGeocode];
    [geocoder reverseGeocodeLocation:lo completionHandler:^(NSArray *placemarks, NSError *error) {
    if(devMode) {
        NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
    }

    if (error == nil && [placemarks count] > 0) {
        // MY CODE - here placemarks is always (null)
    } else {
        if(devMode)
            NSLog(@"%@", error.debugDescription);
    }
}];

大多数情况下,效果很好。但在极少数情况下,我只会收到错误消息:

PBRequester 失败,错误域=NSURLErrorDomain 代码=-1000 “Ungültige URL”用户信息=0x16f5ff30 {NSUnderlyingError=0x16f57810 "Ungültige URL", NSLocalizedDescription=Ungültige URL}

找到地标:(null),错误:Error Domain=kCLErrorDomain Code=2 "操作无法完成。(kCLErrorDomain error 2.)"

我完全不知道为什么会发生这种情况。

【问题讨论】:

    标签: ios7 xcode5 cllocation clgeocoder


    【解决方案1】:

    可以用下面的代码找到地址行,这里要传入经纬度作为参数

    - (void)findAddress:(CLLocationDegrees)latitude with:(CLLocationDegrees)longitude{
    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]);
        }
    }]; }
    

    这里你必须导入以下内容 #import <CoreLocation/CLGeocoder.h>

    【讨论】:

      猜你喜欢
      • 2015-06-04
      • 1970-01-01
      • 1970-01-01
      • 2020-07-02
      • 2017-03-14
      • 2018-11-04
      • 2017-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多