我正在使用以下代码,该代码失败并且不会进入函数内部。
geocoder.geocodeAddressString(location, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in //Fails here
let placemark = placemarks?.first
let lat = placemark?.location?.coordinate.latitude
let lon = placemark?.location?.coordinate.longitude
print("Lat: \(lat), Lon: \(lon)")
} as! CLGeocodeCompletionHandler )
请帮忙! 在此先感谢: - )
答案 0 :(得分:0)
您使用了错误的语法,Swift 3中没有参数标签,NSError
已替换为Error
:
geocoder.geocodeAddressString(location) { (placemarks, error) in
if let placemark = placemarks?.first, let location = placemark.location {
let lat = location.coordinate.latitude
let lon = location.coordinate.longitude
print("Lat: \(lat), Lon: \(lon)")
}
}