我目前有此设置,在计算距离时,我希望从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]];

10-07 14:00