From 47f1d7bb94c7d02e49de5d78e210db6859dffae1 Mon Sep 17 00:00:00 2001 From: ystsoi Date: Sat, 25 Apr 2020 05:38:23 +0800 Subject: [PATCH] Fix an issue that the heading indicator does not rotate if Settings > Privacy > Location Services > System Services > Compass Calibration is off (#247) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix an issue that the heading indicator does not rotate if Settings > Privacy > Location Services > System Services > Compass Calibration is off. * Update CHANGELOG.md Co-authored-by: Nishant Karajgikar Co-authored-by: Minh Nguyễn --- platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLFaux3DUserLocationAnnotationView.m | 5 +++-- platform/ios/src/MGLUserLocation.m | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 294e120f5..0c3e66eee 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -41,6 +41,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Added the `MGLMapView.minimumPitch` and `MGLMapView.maximumPitch` properties to further limit how much the user or your code can tilt the map. ([#208](https://github.com/mapbox/mapbox-gl-native-ios/pull/208)) * Fixed a crash while quitting the application after adding an annotation to `MGLMapView`. ([#252](https://github.com/mapbox/mapbox-gl-native-ios/pull/252)) +* Fixed an issue where the user location annotation view’s heading indicator did not rotate if Compass Calibration was disabled in the device’s Location Services settings. ([#247](https://github.com/mapbox/mapbox-gl-native-ios/pull/247)) * Improved performance when continuously animating a tilted map. ([#16287](https://github.com/mapbox/mapbox-gl-native/pull/16287)) * Fixed a memory leak when zooming with any options enabled in the `MGLMapView.debugMask` property. ([#15179](https://github.com/mapbox/mapbox-gl-native/issues/15179)) diff --git a/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m b/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m index a1d9fb1d4..30ab7de26 100644 --- a/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m +++ b/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m @@ -267,9 +267,10 @@ const CGFloat MGLUserLocationHeadingUpdateThreshold = 0.01; _oldHeadingAccuracy = headingAccuracy; } - if (self.userLocation.heading.trueHeading >= 0) + CLLocationDirection headingDirection = (self.userLocation.heading.trueHeading >= 0 ? self.userLocation.heading.trueHeading : self.userLocation.heading.magneticHeading); + if (headingDirection >= 0) { - CGFloat rotation = -MGLRadiansFromDegrees(self.mapView.direction - self.userLocation.heading.trueHeading); + CGFloat rotation = -MGLRadiansFromDegrees(self.mapView.direction - headingDirection); // Don't rotate if the change is imperceptible. if (fabs(rotation) > MGLUserLocationHeadingUpdateThreshold) diff --git a/platform/ios/src/MGLUserLocation.m b/platform/ios/src/MGLUserLocation.m index 245cbf437..81deb496c 100644 --- a/platform/ios/src/MGLUserLocation.m +++ b/platform/ios/src/MGLUserLocation.m @@ -91,7 +91,7 @@ NS_ASSUME_NONNULL_END - (void)setHeading:(CLHeading *)newHeading { - if (newHeading.trueHeading != _heading.trueHeading) + if (newHeading.trueHeading != _heading.trueHeading || newHeading.magneticHeading != _heading.magneticHeading) { [self willChangeValueForKey:@"heading"]; _heading = newHeading;