距离的字符串

给定 CLLocationDistance(简称为表示米的 Double),输出用户可读的字符串:

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"

默认情况下,这会考虑用户的区域设置。