Skip to content

Commit 4d071e8

Browse files
author
Jill Cardamon
committed
Initial fix.
1 parent 2700814 commit 4d071e8

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Sources/MapboxCoreNavigation/NavigationService.swift

+19
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,28 @@ extension MapboxNavigationService: CLLocationManagerDelegate {
553553
// MARK: Handling LocationManager Output
554554

555555
public func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
556+
// Check if device orientation has changed and inform the location provider accordingly.
557+
updateHeadingForCurrentDeviceOrientation()
558+
print("!!! device orientation: \(UIDevice.current.orientation)")
559+
updateHeadingForCurrentDeviceOrientation()
556560
router.locationManager?(manager, didUpdateHeading: newHeading)
557561
}
558562

563+
public func updateHeadingForCurrentDeviceOrientation() {
564+
var orientation: CLDeviceOrientation
565+
switch UIDevice.current.orientation {
566+
case .landscapeLeft:
567+
orientation = .landscapeRight
568+
case .landscapeRight:
569+
orientation = .landscapeLeft
570+
default:
571+
orientation = .portrait
572+
}
573+
if locationManager.headingOrientation != orientation {
574+
locationManager.headingOrientation = orientation
575+
}
576+
}
577+
559578
public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
560579
//If we're always simulating, make sure this is a simulated update.
561580
if simulationMode == .always, manager != simulatedLocationSource { return }

Sources/MapboxNavigation/NavigationViewController.swift

+12
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.
@@ -829,6 +838,9 @@ extension NavigationViewController: NavigationServiceDelegate {
829838

830839
let movePuckToCurrentLocation = !(userArrivedAtWaypoint && snapsUserLocationAnnotationToRoute && preventRerouting)
831840
if movePuckToCurrentLocation {
841+
if progress.currentLegProgress.currentStep.transportType == .walking && navigationMapView?.mapView.location.options.puckBearingSource == .course {
842+
navigationMapView?.mapView.location.options.puckBearingSource = .heading
843+
}
832844
navigationMapView?.moveUserLocation(to: location, animated: true)
833845
}
834846

Sources/MapboxNavigation/NavigationViewportDataSource.swift

+1
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)