在CLLocationDistance中从Km更改为Miles

时间:2014-03-14 04:08:57

标签: ios objective-c

我目前有这个设置,我很乐意在计算距离时从Km改为Miles。这是我目前的代码:

CLLocation *userloc = [[CLLocation alloc] initWithLatitude:locationManager.location.coordinate.latitude longitude:locationManager.location.coordinate.longitude];
CLLocation *loc = [[CLLocation alloc] initWithLatitude:lat longitude:lon];

CLLocationDistance distance2 = [userloc distanceFromLocation:loc]/ 1000;
NSLog(@"%f",distance2);

[distance setText:[NSString stringWithFormat:@"%.2f km", distance2]];
}

1 个答案:

答案 0 :(得分:14)

这是一个简单的转换:

CLLocationDistance distance2 = [userloc distanceFromLocation:loc] * 0.000621371;
NSLog(@"%f",distance2);

[distance setText:[NSString stringWithFormat:@"%.2f mi", distance2]];