我目前有这个设置,我很乐意在计算距离时从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]];
}
答案 0 :(得分:14)
这是一个简单的转换:
CLLocationDistance distance2 = [userloc distanceFromLocation:loc] * 0.000621371;
NSLog(@"%f",distance2);
[distance setText:[NSString stringWithFormat:@"%.2f mi", distance2]];