Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change from Km to Miles in CLLocationDistance

I have currently this setup and I would love to change from Km to Miles in calculating distance. Here's my current code:

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]];
}
like image 554
user3288168 Avatar asked Mar 14 '14 04:03

user3288168


1 Answers

It's a simple conversion:

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

[distance setText:[NSString stringWithFormat:@"%.2f mi", distance2]];
like image 58
rmaddy Avatar answered Nov 15 '22 01:11

rmaddy