CLGeocoder reverse geocoding fails with Error Domain=NSURLErrorDomain Code=-1000 -

不问归期 提交于 2019-12-06 00:44:01

问题


With a CLLocation object (content e.g. latitude = 48.196169, longitude = 11.620237), I try to get the current city and country like:

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);
    }
}];

mostly, that works great. But in rarely cases, I just get the errors:

PBRequester failed with Error Error Domain=NSURLErrorDomain Code=-1000 "Ungültige URL" UserInfo=0x16f5ff30 {NSUnderlyingError=0x16f57810 "Ungültige URL", NSLocalizedDescription=Ungültige URL}

Found placemarks: (null), error: Error Domain=kCLErrorDomain Code=2 "The operation couldn’t be completed. (kCLErrorDomain error 2.)"

I've absolutely no idea why this happens.


回答1:


You can use the following code to find the address line, here you have to pass latitude and longitude as a parameter

- (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]);
    }
}]; }

Here you have to import the following #import <CoreLocation/CLGeocoder.h>



来源:https://stackoverflow.com/questions/22512566/clgeocoder-reverse-geocoding-fails-with-error-domain-nsurlerrordomain-code-1000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!