我一直在尋找這個,但無法找到答案,我希望將我的經度和緯度轉換爲純文本地址。因爲我想在標記片段中添加地址。 在此先感謝。如何將谷歌縱橫經緯度轉換爲GoogleMaps中Swift中的地址?
[編輯] 這裏是我的代碼
var Addressxx: String = ""
let reverseGeoCoder = GMSGeocoder()
reverseGeoCoder.reverseGeocodeCoordinate(coor, completionHandler: {(placeMark, error) -> Void in
if error == nil {
if let placeMarkObject = placeMark {
if placeMarkObject.results()?.count > 0 {
Addressxx = (placeMarkObject.firstResult()?.lines)! // Error can't assign [String] to 'String'
} else {
//Do Nothing
}
} else {
//Do Nothing
}
} else {
print(error?.localizedDescription)
}
})
let time :String = NSLocalizedString("Tracked on: ", comment:"Tracked on: ") + dfmatter.stringFromDate(date)
let unit = self.speed_unit
let typeStr = dicz.objectForKey("type") as! String
if (dicz.allKeys[2] as! String == "battery"){
let speed:String = NSLocalizedString("Speed: ", comment:"Speed: ") + (dicz.objectForKey("speed")?.stringValue)! + "/" + unit
let battery :String = NSLocalizedString("battery: ", comment:"battery: ") + (dicz.objectForKey("battery")?.stringValue)! + "%"
marker.snippet = battery + "\n" + time + speed + "(" + typeStr + ")"
} else {
let typeStr = dicz.objectForKey("type") as! String
let speed:String = NSLocalizedString("Speed: ", comment:"Speed: ") + (dicz.objectForKey("speed")?.stringValue)! + "/" + unit + typeStr
marker.snippet = Addressxx + "\n" + time + "\n" + speed + "\n" + "Type: (" + typeStr + ")"
}
你有沒有試過我的答案? –
我嘗試添加它,但它使我無法指定類型[String]的值來鍵入'String'。我將它添加到我的我的變量地址Addressxx =(placeMarkObject.firstResult()?. lines)! –
(placeMarkObject.firstResult()?. lines)!是一個字符串數組。所以你的變量「地址」必須聲明如下。 var address = [String]() –