Reputation: 63
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]];
}
Upvotes: 6
Views: 6448
Reputation: 318854
It's a simple conversion:
CLLocationDistance distance2 = [userloc distanceFromLocation:loc] * 0.000621371;
NSLog(@"%f",distance2);
[distance setText:[NSString stringWithFormat:@"%.2f mi", distance2]];
Upvotes: 14