距離的字串

給定 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"

預設情況下,這會考慮使用者的區域設定。