summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2017-09-11 02:23:14 -0700
committerMinh Nguyễn <mxn@1ec5.org>2017-11-02 15:19:55 -0700
commit160da060963548e6e87886ccd493579ccd92a5fd (patch)
treed48a61f66ced4c7db26499674eb750edb4a561f3
parentb475f4c282a8cd97f1cf04c1d2ae5cb4e99c9dce (diff)
downloadqtlocation-mapboxgl-160da060963548e6e87886ccd493579ccd92a5fd.tar.gz
[ios] Refined announced elevation units
-rw-r--r--platform/ios/src/MGLMapAccessibilityElement.m20
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) {