Skip to content

Commit 3ec0e3f

Browse files
author
Jill Cardamon
committed
Initial fix.
1 parent 643bd18 commit 3ec0e3f

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
@@ -583,9 +583,28 @@ extension MapboxNavigationService: CLLocationManagerDelegate {
583583
// MARK: Handling LocationManager Output
584584

585585
public func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
586+
// Check if device orientation has changed and inform the location provider accordingly.
587+
updateHeadingForCurrentDeviceOrientation()
588+
print("!!! device orientation: \(UIDevice.current.orientation)")
589+
updateHeadingForCurrentDeviceOrientation()
586590
router.locationManager?(manager, didUpdateHeading: newHeading)
587591
}
588592

593+
public func updateHeadingForCurrentDeviceOrientation() {
594+
var orientation: CLDeviceOrientation
595+
switch UIDevice.current.orientation {
596+
case .landscapeLeft:
597+
orientation = .landscapeRight
598+
case .landscapeRight:
599+
orientation = .landscapeLeft
600+
default:
601+
orientation = .portrait
602+
}
603+
if locationManager.headingOrientation != orientation {
604+
locationManager.headingOrientation = orientation
605+
}
606+
}
607+
589608
public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
590609
//If we're always simulating, make sure this is a simulated update.
591610
if simulationMode == .always, manager != simulatedLocationSource { return }

Sources/MapboxNavigation/NavigationViewController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
5050
navigationMapView.navigationCamera.viewportDataSource = NavigationViewportDataSource(navigationMapView.mapView,
5151
viewportDataSourceType: .active)
5252
navigationMapView.navigationCamera.follow()
53+
54+
let viewportDataSource = navigationMapView.navigationCamera.viewportDataSource as? NavigationViewportDataSource
55+
print("!!! orientation: \(navigationService.locationManager.headingOrientation)")
56+
// print("!!! device orientation: \(UIDevice.current.orientation)")
57+
// if navigationService.locationManager.headingOrientation == .landscapeLeft {
58+
// print("!!! landscape left")
59+
// } else if navigationService.locationManager.headingOrientation == .landscapeRight {
60+
// print("!!! landscape right")
61+
// }
5362
}
5463

5564
// In case if `NavigationMapView` instance was injected - do not set initial camera options.
@@ -914,6 +923,9 @@ extension NavigationViewController: NavigationServiceDelegate {
914923

915924
let movePuckToCurrentLocation = !(userArrivedAtWaypoint && snapsUserLocationAnnotationToRoute && preventRerouting)
916925
if movePuckToCurrentLocation {
926+
if progress.currentLegProgress.currentStep.transportType == .walking && navigationMapView?.mapView.location.options.puckBearingSource == .course {
927+
navigationMapView?.mapView.location.options.puckBearingSource = .heading
928+
}
917929
navigationMapView?.moveUserLocation(to: location, animated: true)
918930
}
919931

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)