我正在尝试将位置(CLLocation)解析为字符串。
func locationToString (currentLocation: CLLocation) -> String? {
var whatToReturn: String?
CLGeocoder().reverseGeocodeLocation(currentLocation, completionHandler: { (placemarks: [AnyObject]!, error: NSError!) in
if error == nil && placemarks.count > 0 {
let location = placemarks[0] as CLPlacemark
whatToReturn = "\(location.locality) \(location.thoroughfare) \(location.subThoroughfare)"
}
})
return whatToReturn
}
显然,whatToReturn 总是返回 null,因为 completionHandler 在后台运行。我很难理解完成处理程序完成后如何更新我的字符串?
谢谢。