【发布时间】:2019-05-15 13:51:46
【问题描述】:
我在 Swift 4 中找到了一段很棒的反向地理编码代码:Reverse geocoding in Swift 4
我不明白这里发生了什么:
func geocode(latitude: Double, longitude: Double, completion: @escaping (CLPlacemark?, Error?) -> ()) {
CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: latitude, longitude: longitude)) { completion($0?.first, $1) }
}
从这里调用它之后:
geocode(latitude: -22.963451, longitude: -43.198242) { placemark, error in
guard let placemark = placemark, error == nil else { return }
// you should always update your UI in the main thread
DispatchQueue.main.async {
// update UI here
print("address1:", placemark.thoroughfare ?? "")
print("address2:", placemark.subThoroughfare ?? "")
print("city:", placemark.locality ?? "")
print("state:", placemark.administrativeArea ?? "")
print("zip code:", placemark.postalCode ?? "")
print("country:", placemark.country ?? "")
}
}
谁能解释一下。
【问题讨论】:
标签: ios swift mapkit geocoding