13

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?

sanjana
  • 3,034
  • 2
  • 25
  • 31
Learnin
  • 1,221
  • 4
  • 15
  • 19
  • If, rather than `String`, you used `NSString`, then you can use `doubleValue` to get the numeric value which could then be used as parameters to `CLLocationCoordinate2D`. – Rob Feb 09 '15 at 19:34

1 Answers1

22

Use the doubleValue property:

let MomentaryLatitude = (snapshot.value["latitude"] as NSString).doubleValue
let MomentaryLongitude = (snapshot.value["longitude"] as NSString).doubleValue
sanjana
  • 3,034
  • 2
  • 25
  • 31
fred02138
  • 3,323
  • 1
  • 14
  • 17