【发布时间】:2015-06-18 12:33:03
【问题描述】:
我遇到了reverseGeocodeLocation 的一些奇怪问题。这就是我所做的。
我从一个view controller 推送到另一个。视图出现后,我调用当前位置。在didUpdateLocations delegate 中,当我收到当前位置时,我调用reverseGeocodeLocation 来获取地标值。
问题
- 有时它会像魅力一样发挥作用
- 有时它会等待并在长时间间隔后显示结果
- 有时我没有得到任何结果。
下面是我获取反向地理位置的代码
- (void)getReverseLocation
{
__block CLPlacemark* placemark;
CLGeocoder* geocoder = [CLGeocoder new];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
{
if(error)
NSLog(@">>>>>>>> Error in reverseGeoLocation - %@", [error localizedDescription]);
if (error == nil && [placemarks count] > 0)
{
placemark = [placemarks lastObject];
completionBlock(placemark);
}
}];
}
我不确定它为什么会这样。我在同一个位置,互联网连接良好。
这是因为线程吗?我也在主线程上试过这个。但同样的问题。
编辑:我得到了这个错误,经过一些尝试
reverseGeoCodeLocation 出错 - The operation couldn’t be completed. (kCLErrorDomain error 8.)
【问题讨论】:
-
它是一种网络服务,具有速率和其他限制,请参阅 Apple 文档。检查错误并打印错误以查看原因。将错误信息添加到问题中。同时显示你的代码,尤其是completionHandler代码。
-
是的 Zaph,刚刚看到文档。我认为没有选择,而不是等待它得到结果。有没有其他解决办法。
-
我正在尝试捕捉错误。但它现在没有出现。一旦我遇到它,我会分享它。 :)
-
我收到了错误,并在问题部分进行了更新。当我检查错误代码 8 时,它等于 kCLErrorGeocodeFoundNoResult
标签: ios cllocation reverse-geocoding clgeocoder