String from distance
suggest changeGiven a CLLocationDistance (simply a Double representing meters), output a user-readable string:
let distance = CLLocationDistance(42)
let formatter = MKDistanceFormatter()
let answer = formatter.stringFromDistance(distance)
// answer = "150 feet"
Objective-C
CLLocationDistance distance=42;
MKDistanceFormatter *formatter=[[MKDistanceFormatter alloc]init];
NSString *answer=[formatter stringFromDistance:distance];
// answer = "150 feet"
By default, this respects the user’s locale. The Swift call is Swift 2. "150 feet" is one US-locale rounding of 42 meters, not the string for every locale.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents