快速将String转换为CLLocationCoordinate

快速将String转换为CLLocationCoordinate

本文介绍了快速将String转换为CLLocationCoordinate2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

using Firebase as my backend, I've got a series of strings that are latitude and longitude coordinates, how can I convert them to CLLocationCoordinate2D so that I can use them for annotations?Here is the code that gets the info from Firebase every time its updated

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)

}

最后一行不起作用,应该改用什么?

The last line doesn't work, what should I use instead?

推荐答案

使用 doubleValue 属性:

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

这篇关于快速将String转换为CLLocationCoordinate2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 10:46