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