Fix heading display

This commit is contained in:
Ilya Laktyushin 2020-10-27 19:00:51 +04:00
parent 2d39bdc16b
commit 28e2c78c81
2 changed files with 23 additions and 3 deletions

View File

@ -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)
}
}
}

View File

@ -544,8 +544,15 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
}
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
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) {
self.presentationData = presentationData