【发布时间】:2015-01-02 23:16:32
【问题描述】:
我正在尝试将位置 (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 在后台运行。 我很难理解如何在完成处理程序完成时更新我的字符串?
谢谢。
【问题讨论】:
-
你对字符串的最终目标是什么?这必须在完成块的某个地方触发。
-
我想使用字符串 (whatToReturn) 并将其放入 textField 中。但是,我没有从控制器本身使用这个方法,所以我需要一种方法来更新返回的字符串......
-
最好的方法可能是在完成块中设置你的 textField 的文本。 [查看答案]
-
最好的?我确定不是。这是最简单的(:
标签: ios swift cllocation clgeocoder cllocationcoordinate2d