diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2017-09-11 02:23:14 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2017-11-02 15:19:55 -0700 |
commit | 160da060963548e6e87886ccd493579ccd92a5fd (patch) | |
tree | d48a61f66ced4c7db26499674eb750edb4a561f3 | |
parent | b475f4c282a8cd97f1cf04c1d2ae5cb4e99c9dce (diff) | |
download | qtlocation-mapboxgl-160da060963548e6e87886ccd493579ccd92a5fd.tar.gz |
[ios] Refined announced elevation units
-rw-r--r-- | platform/ios/src/MGLMapAccessibilityElement.m | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/platform/ios/src/MGLMapAccessibilityElement.m b/platform/ios/src/MGLMapAccessibilityElement.m index aa1912c4b6..a592a9bcd8 100644 --- a/platform/ios/src/MGLMapAccessibilityElement.m +++ b/platform/ios/src/MGLMapAccessibilityElement.m @@ -111,11 +111,23 @@ CLLocationDirection MGLDirectionBetweenCoordinates(CLLocationCoordinate2D firstC [facts addObject:attributes[@"maki"]]; } - NSNumber *elevation = attributes[@"elevation_m"]; - if (elevation) { - MGLDistanceFormatter *formatter = [[MGLDistanceFormatter alloc] init]; + // Announce the peak’s elevation in the preferred units. + if (attributes[@"elevation_m"] ?: attributes[@"elevation_ft"]) { + NSLengthFormatter *formatter = [[NSLengthFormatter alloc] init]; formatter.unitStyle = NSFormattingUnitStyleLong; - [facts addObject:[formatter stringFromDistance:elevation.doubleValue]]; + + NSNumber *elevationValue; + NSLengthFormatterUnit unit; + BOOL usesMetricSystem = ![[formatter.numberFormatter.locale objectForKey:NSLocaleMeasurementSystem] + isEqualToString:@"U.S."]; + if (usesMetricSystem) { + elevationValue = attributes[@"elevation_m"]; + unit = NSLengthFormatterUnitMeter; + } else { + elevationValue = attributes[@"elevation_ft"]; + unit = NSLengthFormatterUnitFoot; + } + [facts addObject:[formatter stringFromValue:elevationValue.doubleValue unit:unit]]; } if (facts.count) { |