Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a String to CLLocationDistance

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.

like image 380
Seck Ghost Avatar asked Feb 01 '26 23:02

Seck Ghost


1 Answers

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.

like image 177
Christian Avatar answered Feb 03 '26 20:02

Christian