将字符串转换为CLLocationCoordinate2D

前端之家收集整理的这篇文章主要介绍了将字符串转换为CLLocationCoordinate2D前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用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)

}

最后一行不行,应该用什么呢?

使用doubleValue属性
let MomentaryLatitude = (snapshot.value["latitude"] as NSString).doubleValue
let MomentaryLongitude = (snapshot.value["longitude"] as NSString).doubleValue
原文链接:https://www.f2er.com/swift/318947.html

猜你在找的Swift相关文章