CLGeocoder反向地理编码失败,错误域= NSURLErrorDomain Code =

编程入门 行业动态 更新时间:2024-10-26 10:28:45
本文介绍了CLGeocoder反向地理编码失败,错误域= NSURLErrorDomain Code = -1000 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用CLLocation对象(内容例如纬度= 48.196169,经度= 11.620237),我尝试获取当前的城市和国家:

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失败,错误错误域= NSURLErrorDomain代码= -1000 UngültigeURLUserInfo = 0x16f5ff30 {NSUnderlyingError = 0x16f57810 UngültigeURL,NSLocalizedDescription =UngültigeURL}

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

找到地标:(null),错误:错误域= kCLErrorDomain Code = 2 操作无法完成。(kCLErrorDomain错误2。)

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.

推荐答案

您可以使用以下代码查找地址行,在此您必须通过纬度和经度作为参数

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

在这里你必须导入以下 #import< ; CoreLocation / CLGeocoder.h>

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

更多推荐

CLGeocoder反向地理编码失败,错误域= NSURLErrorDomain Code =

本文发布于:2023-11-26 05:44:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632866.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地理   错误   CLGeocoder   NSURLErrorDomain   Code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!