我有谷歌地圖反向地址解析的問題,當談到設置UILabel的文本到反向地理編碼地址。 UILabel在XIB中用作自定義infowindow。我對其他數據的其他信息窗口定製該工作正常但是,看來,當我嘗試設置反向地理回調/完成處理程序內標籤的文本,這是行不通的。這裏是我到目前爲止的代碼,我已經嘗試過多種方式,包括將它分配給變量,並且我還沒有能夠獲得任何工作。谷歌地圖iOS版反向地理編碼
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
任何幫助肯定是讚賞!
不幸的是這不會工作。外部函數必須採用座標,並且基本上返回地址。我修改了你提供的開始指向接受座標,但是,當我調用getAddress()時,它會按照預期返回地址,但我仍然無法將UILabel文本設置爲infoWindow中的地址。 – recoilnetworks
發佈您修改的代碼 – Rob
這是正確的答案,非常感謝 – 2017-08-11 21:26:16