【发布时间】:2021-08-30 19:51:01
【问题描述】:
我有以下来自 GPS 坐标的功能地理编码地址
private func getAddressFromLocation(forLocation: CLLocationCoordinate2D) {
let geoCoder = CLGeocoder()
geoCoder.reverseGeocodeLocation(CLLocation(latitude: forLocation.latitude, longitude: forLocation.longitude), completionHandler: {(places, error) in
guard error == nil else {
return
}
let place: CLPlacemark = places!.first!
var address: [String] = []
if place.country != nil { address.append(place.country!) }
if place.postalCode != nil { address.append(place.postalCode!) }
if place.locality != nil { address.append(place.locality!) }
if place.thoroughfare != nil { address.append(place.thoroughfare!) }
self.fullAddress = address.joined(separator: ",")
})
}
从我的应用程序的另一部分调用函数,我想知道如何确保程序将等到 fullAddress 变量获得值(函数完成)。我试图将函数调用放入同步调度队列,但没有帮助。 感谢您的任何建议。
【问题讨论】:
-
不要问,要告诉。意思是:不要等待,通知。请搜索completion handler
标签: swift clgeocoder