我一直在寻找这个,但无法找到答案,我希望将我的经度和纬度转换为纯文本地址。因为我想在标记片段中添加地址。 在此先感谢。如何将谷歌纵横经纬度转换为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]() –