3

I cannot find any examples of how to convert a String to CLLocationDistance. For example:

let distance : String = "2000.0"
let mdf = MKDistanceFormatter()
mdf.units = .Metric
var clDistance = mdf.distanceFromString(distance)

I always get clDistance = -1.

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
Seck Ghost
  • 43
  • 2

1 Answers1

5

You need to clarify what the 2000 are. Meters, Kilometers etc. Like that:

let distance : String = "2000.0m"
let mdf = MKDistanceFormatter()
mdf.units = .Metric
var clDistance = mdf.distanceFromString(distance)

The distanceFromString returns the distance as meters.

Christian
  • 22,585
  • 9
  • 80
  • 106