reverseGeocodeLocation在iOS 11.4中未提供地址

时间:2018-07-01 11:59:54

标签: ios swift cllocation clgeocoder cllocationcoordinate2d

我正在使用以下代码通过纬度和经度获取地址

func getAddressFromLatLon(latitude: Double, withLongitude longitude: Double) {
    var center : CLLocationCoordinate2D = CLLocationCoordinate2D()
    let lat: Double = Double("\(latitude)")!
    let lon: Double = Double("\(longitude)")!
    let ceo: CLGeocoder = CLGeocoder()
    center.latitude = lat
    center.longitude = lon

    let loc: CLLocation = CLLocation(latitude:center.latitude, longitude: center.longitude)

    ceo.reverseGeocodeLocation(loc, completionHandler:
        {(placemarks, error) in
            if (error != nil) {
                print("reverse geodcode fail: \(error!.localizedDescription)")
            }
            if (placemarks != nil) {
                print(placemarks!)
            }
    })
}

它在iOS 11.3中运行良好,现在我在iOS 11.4中尝试了它,它给我的错误是“ 反向地址解析器失败,并显示错误操作无法完成。(kCLErrorDomain错误2。 )”。

我检查了thisthis SO链接,但我没有提出更多要求,它在iOS 11.3中也能正常工作。代码中有任何错误或我想更新代码以支持iOS 11.4吗?

0 个答案:

没有答案