String 在swift中将字符串转换为CLLocationCoordinate2D
使用Firebase作为后端,我有一系列的字符串,它们是纬度和经度坐标,如何将它们转换为CLLocationCoordinate2D,以便用于注释? 下面是每次更新Firebase时从Firebase获取信息的代码String 在swift中将字符串转换为CLLocationCoordinate2D,string,swift,converter,cllocation,cllocationcoordinate2d,String,Swift,Converter,Cllocation,Cllocationcoordinate2d,使用Firebase作为后端,我有一系列的字符串,它们是纬度和经度坐标,如何将它们转换为CLLocationCoordinate2D,以便用于注释? 下面是每次更新Firebase时从Firebase获取信息的代码 var UpdateRef = Firebase(url:"https://ici.firebaseio.com/users") UpdateRef.observeEventType(.ChildChanged, withBlock: { (snapshot) in let
var UpdateRef = Firebase(url:"https://ici.firebaseio.com/users")
UpdateRef.observeEventType(.ChildChanged, withBlock: { (snapshot) in
let MomentaryLatitude = snapshot.value["latitude"] as? String
let MomentaryLongitude = snapshot.value["longitude"] as? String
let ID = snapshot.value["ID"] as? String
println("\(MomentaryLatitude)")
var Coordinates = CLLocationCoordinate2D(latitude: MomentaryLatitude as
CLLocationDegrees, longitude: MomentaryLongitude as CLLocationDegrees)
}
最后一行行不通,我应该用什么来代替?使用
doubleValue
属性:
let MomentaryLatitude = (snapshot.value["latitude"] as NSString).doubleValue
let MomentaryLongitude = (snapshot.value["longitude"] as NSString).doubleValue
如果使用的不是
String
,而是NSString
,则可以使用doubleValue
获取数值,该数值可以用作CLLocationCoordinate2D
的参数。