【发布时间】:2016-09-19 06:19:21
【问题描述】:
在将 UILabel 的文本设置为反向地理编码地址时,我遇到了 Google 地图反向地理编码的问题。 UILabel 在 XIB 中用作自定义信息窗口。我有另一个可以正常工作的其他数据的自定义信息窗口,但是,当我尝试在反向地理编码回调/完成处理程序中设置标签的文本时,它似乎不起作用。这是我到目前为止的代码,我已经尝试了多种方法,包括将其分配给变量,但我无法让任何工作。
let infoWindow = NSBundle.mainBundle().loadNibNamed("InfoWindowCurrent", owner: self, options: nil)[0] as! InfoWindowCurrent
let geocoder = GMSGeocoder()
let coordinate = CLLocationCoordinate2DMake(Double(self.locLatitude)!, Double(self.locLongitude)!)
var currentAddress = String()
geocoder.reverseGeocodeCoordinate(coordinate) { response , error in
if let address = response?.firstResult() {
let lines = address.lines! as [String]
currentAddress = lines.joinWithSeparator("\n")
}
}
infoWindow.labelAddressStreet.text = currentAddress
return infoWindow
我也试过这个:
let infoWindow = NSBundle.mainBundle().loadNibNamed("InfoWindowCurrent", owner: self, options: nil)[0] as! InfoWindowCurrent
let geocoder = GMSGeocoder()
let coordinate = CLLocationCoordinate2DMake(Double(self.locLatitude)!, Double(self.locLongitude)!)
geocoder.reverseGeocodeCoordinate(coordinate) { response , error in
if let address = response?.firstResult() {
let lines = address.lines! as [String]
infoWindow.labelAddressStreet.text = lines.joinWithSeparator("\n")
}
}
return infoWindow
一切都正确连接,因为以下代码有效:
let infoWindow = NSBundle.mainBundle().loadNibNamed("InfoWindowCurrent", owner: self, options: nil)[0] as! InfoWindowCurrent
let geocoder = GMSGeocoder()
let coordinate = CLLocationCoordinate2DMake(Double(self.locLatitude)!, Double(self.locLongitude)!)
geocoder.reverseGeocodeCoordinate(coordinate) { response , error in
if let address = response?.firstResult() {
let lines = address.lines! as [String]
}
}
infoWindow.labelAddressStreet.text = "Unable to reverse geocode location!"
return infoWindow
非常感谢任何帮助!
【问题讨论】:
标签: ios swift google-maps reverse-geocoding