CLGeocoder reverseGeocodeLocation“kCLErrorDomain error 2”
我正在开发一个具有反向地理编码function的iOS应用程序。 当我第一次调用函数时,一切都很好。 第二次调用后(使用控制器的新实例进行调用)出现“Domain = kCLErrorDomain Code = 2”错误。 这发生在模拟器和设备上。 坐标是有效的。 我的代码:
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]); } }];
提前致谢!!
错误2通常意味着您经常调用地理位置服务器。 通常情况下,每次委派方法didUpdateLocations被触发时,都会向服务器发送反向地理编码请求。 在文档中,苹果公司表示这通常只能每分钟进行一次。
关于这个错误的更多信息可以在苹果的文档kCLErrorDomain: 核心位置常量参考和CLError.h
中CLError.h
:
kCLErrorNetwork
networking不可用或发生networking错误。