ios - 在 CLLocationDistance 中从 Km 更改为 Miles

标签 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]];
}

最佳答案

这是一个简单的转换:

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

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

关于ios - 在 CLLocationDistance 中从 Km 更改为 Miles,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22395917/

相关文章:

ios - Swift 中 SKScene 中的社交框架

ios - 拦截子类中的 Objective-C 委托(delegate)消息

Objective-C performSelectorInBackground - 调用的方法在哪里运行?

ios - 如何判断协议(protocol)中的哪个方法未实现?

ios - 如何更改 UIPickerView 选择器的颜色

ios - 如何将 UIControl 作为函数参数传递?

c++ - 何时使用 ". "或 "-> "运算符来访问属性或成员函数?

ios - 在 Swift 3 中使用 NSCoder 编码/解码日期?

ios - 使用户无法编辑 UITextView

ios - TouchesBegan 未调用