coudron coudron - 3 months ago 13
iOS Question

Pretty Print Distances for iOS

I have two CLLocation objects and I would like the show the distance between them in a nice and pretty format. Like "22 feet", "58 yards", or "2.3 miles"

CLLocation *location1 = [[CLLocation alloc] initWithLatitude:42.333297 longitude:-71.588858];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:42.353297 longitude:-71.578858];

float target = [location1 getDistanceFrom:location2];

Basically, is there anything in the iOS library that can convert a distance to a pretty string or do I have to do this manually?

Answer Source

Unfortunately, you have to do this manually.

And if you do so, please don't forget to check:

[[[NSLocale currentLocale] objectForKey:NSLocaleUsesMetricSystem] boolValue]

The rest of the world would appreciate.