Google Maps iOS Reverse Geocoding
Ich habe ein Problem mit der umgekehrten Geokodierung von Google Maps, wenn es darum geht, den Text eines UILabels auf die umgekehrte geokodierte Adresse zu setzen. Das UILabel wird in einem XIB als benutzerdefiniertes Infofenster verwendet. Ich habe ein anderes benutzerdefiniertes Infofenster für andere Daten, das ordnungsgemäß funktioniert. Es scheint jedoch, dass es nicht funktioniert, wenn ich versuche, den Text der Beschriftung im Reverse-Geocode-Callback- / Completion-Handler festzulegen. Hier ist der Code, den ich bisher habe, und ich habe den Code auf verschiedene Arten ausprobiert, einschließlich der Zuweisung zu Variablen, und ich konnte nichts zum Laufen bringen.
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
Ich habe es auch versucht:
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
Alles ist korrekt verbunden, da der folgende Code funktioniert:
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
Jede Hilfe wird auf jeden Fall geschätzt!