- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用CLGeocoder来确定特定位置的地标的项目。
这样非常简单的调用。
CLGeocoder().geocodeAddressString(location) { (placemarks, error) in
if let error = error {
print(error.localizedDescription)
}
我希望能够捕获CLError代码并做出相应的响应,而不是打印出NSError的localizedDescription。例如,如果找不到该位置,则会打印我的localizedDescription
The operation couldn’t be completed. (kCLErrorDomain error 8.)
在Swift中,如何确定CLError代码,这样我就不必打开将根据用户区域设置更改的某些本地化描述?
最佳答案
您需要将错误转换为CLError
,然后切换错误code
:
if let error = error as? CLError {
switch error.code {
case .locationUnknown:
print("locationUnknown: location manager was unable to obtain a location value right now.")
case .denied:
print("denied: user denied access to the location service.")
case .promptDeclined:
print("promptDeclined: user didn’t grant the requested temporary authorization.")
case .network:
print("network: network was unavailable or a network error occurred.")
case .headingFailure:
print("headingFailure: heading could not be determined.")
case .rangingUnavailable:
print("rangingUnavailable: ranging is disabled.")
case .rangingFailure:
print("rangingFailure: a general ranging error occurred.")
default : break
}
}
关于swift - CLGeocoder()。geocodeAddressString错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65837006/
我有一个简单的问题。 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 时,我只得到一个结果,尽管我知道输入的字符串应该返回多个值。
我是一名优秀的程序员,十分优秀!