gpt4 book ai didi

ios - 在 CLLocationDistance 中从 Km 更改为 Miles

转载 作者:可可西里 更新时间:2023-11-01 03:38:09 26 4
gpt4 key购买 nike

我目前有这个设置,我很想在计算距离时从 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com