【问题标题】:Convert String to CLLocationCoordinate2D in swift快速将字符串转换为 CLLocationCoordinate2D
【发布时间】:2015-04-09 15:35:19
【问题描述】:

使用 Firebase 作为我的后端,我有一系列纬度和经度坐标的字符串,如何将它们转换为 CLLocationCoordinate2D 以便我可以将它们用于注释? 这是每次更新时从 Firebase 获取信息的代码

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)

}

最后一行不起作用,我应该用什么代替?

【问题讨论】:

  • 如果您使用NSString 而不是String,那么您可以使用doubleValue 来获取可以用作CLLocationCoordinate2D 参数的数值。

标签: string swift converter cllocation cllocationcoordinate2d


【解决方案1】:

使用doubleValue 属性:

let MomentaryLatitude = (snapshot.value["latitude"] as NSString).doubleValue
let MomentaryLongitude = (snapshot.value["longitude"] as NSString).doubleValue

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    • 1970-01-01
    相关资源
    最近更新 更多