CLGeocoder reverseGeocodeLocation “kCLErrorDomain error 2”

大兔子大兔子 提交于 2019-12-12 14:13:38

问题


I'm developing an iOS app with reverse geocoding features. When I call the function the first time everything is fine. After the second call (with a new instance of the controller where the call is done) the "Domain=kCLErrorDomain Code=2" Error appears. This happens on the Simulator and on the device. The Coordinates are valid. My Code:

CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
CLLocation *loc = [[CLLocation alloc] initWithLatitude:cityCoords.latitude longitude:cityCoords.longitude];

self.displayedCity = [[Stadt alloc] init];
[geoCoder reverseGeocodeLocation:loc completionHandler:^(NSArray *placemarks, NSError *error) {

    if(!error){
        for (CLPlacemark * placemark in placemarks) {
            self.displayedCity.name         = [placemark locality];
            self.displayedCity.stadtCoord   = placemark.region.center;
        }

        [self loadCity:self.displayedCity.name];

    }
    else{
        NSLog(@"failed getting city: %@", [error description]);
    }

}];

Thanks in advance!!


回答1:


Error 2 usually means that you have called the geolocation server too often. Typically this happens when you send a reverse-Geocoding Request to the server each time the delegate method didUpdateLocations was fired. In the docs Apple says that this should typically only be done once a minute.




回答2:


More info on the this error can be found in Apple's docs on kCLErrorDomain: Core Location Constants Reference and in CLError.h:

kCLErrorNetwork The network was unavailable or a network error occurred.



来源:https://stackoverflow.com/questions/13888076/clgeocoder-reversegeocodelocation-kclerrordomain-error-2

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