13

バックエンドとして 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)

}

最後の行が機能しません。代わりに何を使用すればよいですか?

4

1 に答える 1

22

doubleValue次のプロパティを使用します。

let MomentaryLatitude = (snapshot.value["latitude"] as NSString).doubleValue
let MomentaryLongitude = (snapshot.value["longitude"] as NSString).doubleValue
于 2015-02-09T19:30:19.240 に答える