我正在使用NSLengthFormatter类来格式化用户和某个目的地之间的距离。
现在,如果长度小于1000米,则格式化的距离始终以码或米(取决于语言环境)显示。
例如,如果距离为450.0,则格式化字符串将是492.7 yd或450 m。
我该如何调整NSLengthFormatter,使其仅返回英里/千米的距离字符串?
CLLocation *userLocation; //<- Coordinates fetched from CLLocationManager
CLLocation *targetLocation; //<- Some location retrieved from server data
CLLocationDistance distance = [userLocation distanceFromLocation:targetLocation];
NSLengthFormatter *lengthFormatter = [NSLengthFormatter new];
NSString *formattedLength = [lengthFormatter stringFromMeters:distance];
现在,如果长度小于1000米,则格式化的距离始终以码或米(取决于语言环境)显示。
例如,如果距离为450.0,则格式化字符串将是492.7 yd或450 m。
我该如何调整NSLengthFormatter,使其仅返回英里/千米的距离字符串?
numberFormatter
并尝试调整 NSNumberFormatter 的不同属性吗? - luk2302NSNumberFormatter
轻松完成。 - Droppy