Skip to content

Commit 062bbe3

Browse files
author
Jill Cardamon
committed
Initial fix.
1 parent ab43741 commit 062bbe3

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Sources/MapboxCoreNavigation/NavigationService.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,28 @@ extension MapboxNavigationService: CLLocationManagerDelegate {
611611
// MARK: Handling LocationManager Output
612612

613613
public func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
614+
// Check if device orientation has changed and inform the location provider accordingly.
615+
updateHeadingForCurrentDeviceOrientation()
616+
print("!!! device orientation: \(UIDevice.current.orientation)")
617+
updateHeadingForCurrentDeviceOrientation()
614618
router.locationManager?(manager, didUpdateHeading: newHeading)
615619
}
616620

621+
public func updateHeadingForCurrentDeviceOrientation() {
622+
var orientation: CLDeviceOrientation
623+
switch UIDevice.current.orientation {
624+
case .landscapeLeft:
625+
orientation = .landscapeRight
626+
case .landscapeRight:
627+
orientation = .landscapeLeft
628+
default:
629+
orientation = .portrait
630+
}
631+
if locationManager.headingOrientation != orientation {
632+
locationManager.headingOrientation = orientation
633+
}
634+
}
635+
617636
public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
618637
//If we're always simulating, make sure this is a simulated update.
619638
if simulationMode == .always, manager != simulatedLocationSource { return }

Sources/MapboxNavigation/NavigationViewController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
7474
navigationMapView.navigationCamera.viewportDataSource = NavigationViewportDataSource(navigationMapView.mapView,
7575
viewportDataSourceType: .active)
7676
navigationMapView.navigationCamera.follow()
77+
78+
let viewportDataSource = navigationMapView.navigationCamera.viewportDataSource as? NavigationViewportDataSource
79+
print("!!! orientation: \(navigationService.locationManager.headingOrientation)")
80+
// print("!!! device orientation: \(UIDevice.current.orientation)")
81+
// if navigationService.locationManager.headingOrientation == .landscapeLeft {
82+
// print("!!! landscape left")
83+
// } else if navigationService.locationManager.headingOrientation == .landscapeRight {
84+
// print("!!! landscape right")
85+
// }
7786
}
7887

7988
// In case if `NavigationMapView` instance was injected - do not set initial camera options.
@@ -987,6 +996,9 @@ extension NavigationViewController: NavigationServiceDelegate {
987996

988997
let movePuckToCurrentLocation = !(userArrivedAtWaypoint && snapsUserLocationAnnotationToRoute && preventRerouting)
989998
if movePuckToCurrentLocation {
999+
if progress.currentLegProgress.currentStep.transportType == .walking && navigationMapView?.mapView.location.options.puckBearingSource == .course {
1000+
navigationMapView?.mapView.location.options.puckBearingSource = .heading
1001+
}
9901002
navigationMapView?.moveUserLocation(to: location, animated: true)
9911003
}
9921004

Sources/MapboxNavigation/NavigationViewportDataSource.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public class NavigationViewportDataSource: ViewportDataSource {
125125
NotificationCenter.default.post(name: .navigationCameraViewportDidChange, object: self, userInfo: [
126126
NavigationCamera.NotificationUserInfoKey.cameraOptions: cameraOptions
127127
])
128+
print("!!! device orientation: \(UIDevice.current.orientation)")
128129
}
129130

130131
// MARK: CameraOptions Methods

0 commit comments

Comments
 (0)