diff --git a/submodules/DeviceLocationManager/Sources/DeviceLocationManager.swift b/submodules/DeviceLocationManager/Sources/DeviceLocationManager.swift index 60b1bd5df2..1a20f4e2c1 100644 --- a/submodules/DeviceLocationManager/Sources/DeviceLocationManager.swift +++ b/submodules/DeviceLocationManager/Sources/DeviceLocationManager.swift @@ -119,6 +119,19 @@ public final class DeviceLocationManager: NSObject { } } +extension CLHeading { + var effectiveHeading: Double? { + if self.headingAccuracy < 0.0 { + return nil + } + if self.trueHeading > 0.0 { + return self.trueHeading + } else { + return self.magneticHeading + } + } +} + extension DeviceLocationManager: CLLocationManagerDelegate { public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { assert(self.queue.isCurrent()) @@ -127,7 +140,7 @@ extension DeviceLocationManager: CLLocationManagerDelegate { if self.currentTopMode != nil { self.currentLocation = location for subscriber in self.subscribers { - subscriber.update(location, self.currentHeading?.magneticHeading) + subscriber.update(location, self.currentHeading?.effectiveHeading) } } } @@ -140,7 +153,7 @@ extension DeviceLocationManager: CLLocationManagerDelegate { self.currentHeading = newHeading if let currentLocation = self.currentLocation { for subscriber in self.subscribers { - subscriber.update(currentLocation, newHeading.magneticHeading) + subscriber.update(currentLocation, newHeading.effectiveHeading) } } } diff --git a/submodules/LocationUI/Sources/LocationViewControllerNode.swift b/submodules/LocationUI/Sources/LocationViewControllerNode.swift index 1968bfa591..6c063fccc9 100644 --- a/submodules/LocationUI/Sources/LocationViewControllerNode.swift +++ b/submodules/LocationUI/Sources/LocationViewControllerNode.swift @@ -544,7 +544,14 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan } func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { - self.headerNode.mapNode.userHeading = CGFloat(newHeading.magneticHeading) + if newHeading.headingAccuracy < 0.0 { + self.headerNode.mapNode.userHeading = nil + } + if newHeading.trueHeading > 0.0 { + self.headerNode.mapNode.userHeading = CGFloat(newHeading.trueHeading) + } else { + self.headerNode.mapNode.userHeading = CGFloat(newHeading.magneticHeading) + } } func updatePresentationData(_ presentationData: PresentationData) {