UILabelのテキストを逆ジオコーディングされた住所に設定する際、Google Maps Reverse Geocodingに問題があります。 UILabelはカスタム情報ウィンドウとしてXIBを使用しています。私は別のカスタム情報を持っていますが、これは正しく動作していますが、リバースジオコードコールバック/補完ハンドラ内でラベルのテキストを設定しようとすると動作しません。ここに私がこれまで持っているコードがあり、私はコードに変数を代入することを含め、複数の方法で試してみました。何も動かすことができませんでした。Google Maps 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
これは正解です。ありがとう –