我正在开发具有反向地理编码功能的 iOS 应用程序。当我第一次调用该函数时,一切都很好。第二次调用后(使用完成调用的 Controller 的新实例)出现“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 通常意味着您过于频繁地调用地理定位服务器。通常,当您每次触发委托(delegate)方法 didUpdateLocations 时向服务器发送反向地理编码请求时,就会发生这种情况。在文档中,Apple 表示这通常应该每分钟只执行一次。
关于iphone - CLGeocoder reverseGeocodeLocation "kCLErrorDomain error 2",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13888076/