- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我正在根据这篇文章开发具有反向地理编码功能的 iOS 应用程序:geocoding tutorial
但是当我在模拟器上进行这样的测试时,我得到“kCLErrorDomain 错误 9”。我搜索了很多,只有错误 0 或 1 而不是 9。
这是我在 viewDidLoad
中的代码:
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = 80.0;
[self.locationManager startUpdatingLocation];
CLGeocoder *geocoder = [[[CLGeocoder alloc] init] autorelease];
[geocoder reverseGeocodeLocation:self.locationManager.location
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
if(placemarks && placemarks.count > 0)
{
//do something
CLPlacemark *topResult = [placemarks objectAtIndex:0];
NSString *addressTxt = [NSString stringWithFormat:@"%@ %@,%@ %@",
[topResult subThoroughfare],[topResult thoroughfare],
[topResult locality], [topResult administrativeArea]];
NSLog(@"%@",addressTxt);
}
}];
非常感谢。
最佳答案
核心位置错误代码是 documented here .
代码值 8、9 和 10 是:
kCLErrorGeocodeFoundNoResult,
kCLErrorGeocodeFoundPartialResult,
kCLErrorGeocodeCanceled
根据显示的代码,出现错误 8 的最可能原因是它在调用 startUpdatingLocation
后立即尝试使用 location
,此时它可能仍然为 nil
。
获取当前位置通常需要几秒钟,并且很可能在此之前为 nil
(导致地理编码错误 8 或 kCLErrorGeocodeFoundNoResult
)。我不确定“FoundPartialResult”错误代码 9 的含义,但 Apple 的 GeocoderDemo 示例应用程序以相同的方式处理这两种情况(作为“无结果”)。
尝试将地理编码代码(startUpdatingLocation
调用之后的所有代码)移动到委托(delegate)方法 locationManager:didUpdateToLocation:fromLocation:
。位置管理器将在实际有位置时调用该委托(delegate)方法,只有这样才能安全地使用 location
。
在那里,在地理编码成功(或不成功)之后,您可能需要调用 stopUpdatingLocation
否则它会在每次更新用户位置时尝试进行地理编码。
在尝试对其进行地理编码之前,您可能还想检查接收到的位置的准确性 (newLocation.horizontalAccuracy
) 和时间 (newLocation.timestamp
)。
关于ios - CLGeocoder reverseGeocodeLocation 返回 'kCLErrorDomain error 9',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9526541/
我有一个简单的问题。 MKReverseCoder 已弃用,自 iOS 5 起不再工作。我们必须使用CLGeocoder。但是,iOS4下有很多人。新应用程序如何与 iOS4 和 iOS5 一起使用进
我有一个应用程序可以进行正向地理编码(获取给定地址的坐标)以在 MKMapView 上显示一堆图钉。该应用程序是在 iOS 使用 CLGeocoder 支持正向地理编码之前开发的。 (首次在 iOS
我正在使用CLGeocoder来确定特定位置的地标的项目。 这样非常简单的调用。 CLGeocoder().geocodeAddressString(location) { (placemarks,
我正在尝试找出方法来限制我向 CLGeocoder 发出的请求数量,因为我不断超出最大限制。我得到“Error Domain=kCLErrorDomain Code = 2”(null)”。基本上,每
documentation CLGeocoder 状态: An iOS-based device must have access to the network in order for the ge
我没有在文档中看到任何明确提及的内容: https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLG
您好,我正在使用此方法来获取坐标并向 map View 添加一个邮政编码的图钉 -(void)myMapview { //sitePC is an Array with the Post co
在模拟器中我将位置设置为 Latitude: 38.056709 Longitude: -78.6115 但返回的地标是弗吉尼亚州的。 CLGeocoder *geocoder = [[CLGeoco
在我的 viewDidLoad 中,我有这个方法,可以将 Parse 中的位置转换为城市和州。唯一的问题是,大多数时候它以错误的顺序附加。另外,位置变量末尾的 .location 是一种自定义方法,可
我正在尝试使用由 URL 和城市名称组成的字符串发出 http 请求,使用 CLGeocoder 获取用户的当前位置,然后返回他们所在城市的名称。 string 在调用之前生成,并使用 + 运算符连接
我正在使用 CLGeoCoder 进行正向地理编码。它在 OS > 5.0 的设备中运行良好。 但是应用程序崩溃是操作系统 : dyld: Symbol not found: _OBJC_CL : A
所以我试图让它在完成处理程序之后做一些事情,但我一直收到错误: expected CLGeocodeCompletionHandler class func didCompleteGeocoding(
我正在 iOS 8.0 中开发应用。 通过下面的链接,我正在分配位置对象, How can I get current location from user in iOS 我的目标是根据当前位置找出城
我正在使用 CLGeocoder 在 map 上定位地址并计算用户与一大堆地址的距离。 这是使用 CLGeocoder 的代码部分: CLGeocoder *geocoder = [[CLGeocod
我正在使用 CLGeocoder reverseGeocodeLocation 从坐标中获取地址,似乎在中国返回“地理编码器失败:错误域=kCLErrorDomain 代码=8”操作无法完成。 (kC
我正在为 IOS5 开发一个 iPhone 应用程序。我目前正在使用位于 CoreLocation 框架内的 CLGeocoder 类。我无法弄清楚完成处理程序 block 是否在最后调用,在地理编码
给定经度和纬度不是我的当前位置,我如何使用 GLGeocoder 执行反向地理编码查找? self.geoCoder = [[CLGeocoder alloc] init]; self.locatio
我要复活this和 this问题,因为问题对我来说仍然存在,所以我正在写一个新问题。 这是我的代码: - (SVGeocoder*)initWithParameters:(NSMutableDicti
谁能帮我理解为什么下面的代码会有这样的输出: [ +/- 5.00m (speed 32.65 mps / course 294.26) @ 7/27/16, 4:34:19 AM Eastern D
我在使用 CLGeocoder 时遇到问题,当我调用 geocodeAddressString:withCompletionHandler 时,我只得到一个结果,尽管我知道输入的字符串应该返回多个值。
我是一名优秀的程序员,十分优秀!