Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for initial camera position when snapUserLocationToRoute is enabled #386

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

bjtrounson
Copy link
Collaborator

This is a fix for snapUserLocationToRoute option. When it is enabled on NavigationMapView the camera position is defaulted to Lat: 0.0 Lng: 0.0

This happens even when you have a location provider with an activated listener.

The problem seems to be when the locationEngine.lastLocation is initialized in NavigationMapView. It will check snapUserLocationToRoute option and set the LocationEngines last location to the uiState.snappedLocation.

The problem with this is the current uiState.snappedLocation which when starting the view is null and is not set until navigation has started.

 val locationEngine = remember { StaticLocationEngine() }
  locationEngine.lastLocation =
      if (snapUserLocationToRoute) {
        uiState.snappedLocation?.toAndroidLocation()
      } else {
        uiState.location?.toAndroidLocation()
      }

This PR fixes this by simply adding a extra check for isNavigating on the snapUserLocationToRoute option when the LocationEngine lastLocation is initialized.

@ianthetechie ianthetechie self-requested a review December 9, 2024 01:43
Copy link
Contributor

@ianthetechie ianthetechie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; thanks!

@ianthetechie ianthetechie merged commit 1a59786 into stadiamaps:main Dec 9, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants