Created
December 14, 2011 23:30
-
-
Save pmark/1479097 to your computer and use it in GitHub Desktop.
formattedDistanceFromCurrentLocationWithUnits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOOL useMetricUnits = NO; | |
- (NSString *)formattedDistanceFromCurrentLocationWithUnits:(SM3DARPointOfInterest *)poi | |
{ | |
NSString *formatted; | |
CGFloat distance; | |
if (useMetricUnits) | |
{ | |
// Metric. | |
distance = [poi distanceInMetersFromCurrentLocation]; | |
if (distance >= 1000.0) | |
{ | |
formatted = [NSString stringWithFormat:@"%.1f km", (distance / 1000.0)]; | |
} | |
else | |
{ | |
formatted = [NSString stringWithFormat:@"%i m", (int)(distance)]; | |
} | |
} | |
else | |
{ | |
// Imperial. | |
distance = [poi distanceInMilesFromCurrentLocation]; | |
if (distance < 0.189) | |
{ | |
formatted = [NSString stringWithFormat:@"%i ft", (int)(distance * 5280)]; | |
} | |
else | |
{ | |
formatted = [NSString stringWithFormat:@"%.1f mi", distance]; | |
} | |
} | |
return formatted; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment