mapbox / mapbox/mapbox-navigation-android
Inconsistent Route Drawing Between Screens in Automotive App with MapBox Navigation
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 651
- Forks
- 321
- PR merge metrics
- No merged PRs in 30d
Description
Android API: 33
Mapbox Navigation SDK version: 2.17.3
Steps to trigger behavior
1. Start navigation on the MapBox Screen by searching for a location.
2. Build a route with a vanishing feature and simulate movement along the route using the provided code snippet.
3. Switch screens between with MapBox navigations.
Expected behavior
- Consistent route drawing on both MapBox Navigation windows and in the Automotive app.
- The route should be visible whenever the screens are switched, reflecting the current navigation status.
Actual behavior
- Inconsistency in route drawing when switching screens; the route sometimes is not displayed despite the CPP (Car Positioning Puck) moving along the route.
- The route visualization intermittently disappears, causing navigation display issues.
Issue Description:
I am developing an Automotive app with two displays: the IVI (In-Vehicle Infotainment) and IC (Instrument Cluster). The IVI has a Home screen with a small MapBox Navigation window and an option to navigate to a detailed, full-screen navigation screen. Both screens use MapBox Navigation.
The issue arises when I switch between these screens. Sometimes, the route is not drawn on one of the screens, despite the CPP still following the route path. This inconsistency in route visualization is problematic for the navigation experience.
Here is the code snippet I use for route building and handling:
private val onPositionChangedListener = OnIndicatorPositionChangedListener { point ->
val result = routeLineApi.updateTraveledRouteLine(point)
mapView.getMapboxMap().getStyle()?.apply {
routeLineView.renderRouteLineUpdate(this, result)
}
}
private val routeProgressObserver = RouteProgressObserver { routeProgress ->
onFractionTraveledUpdate(routeProgress.fractionTraveled)
onRemainingDistanceUpdate(
viewModel.getFormattedRemainingDistanceToEndpoint(routeProgress.distanceRemaining)
)
onTravelTimeUpdate(viewModel.getFormattedTravelTime(routeProgress.durationRemaining))
onArrivalTimeUpdate(viewModel.getFormattedArrivalTime(routeProgress.durationRemaining))
viewModel.updateRouteInstructions(routeProgress)
routeLineApi.updateWithRouteProgress(routeProgress) { result ->
mapView.getMapboxMap().getStyle()?.apply {
routeLineView.renderRouteLineUpdate(this, result)
}
}
viewportDataSource.onRouteProgressChanged(routeProgress)
viewportDataSource.evaluate()
}
private val routesObserver: RoutesObserver = RoutesObserver { routeUpdateResult ->
if (routeUpdateResult.navigationRoutes.isNotEmpty()) {
routeLineApi.setNavigationRoutes(
newRoutes = routeUpdateResult.navigationRoutes,
alternativeRoutesMetadata = mapboxNavigation.getAlternativeMetadataFor(
routeUpdateResult.navigationRoutes
)
) { value ->
mapView.getMapboxMap().getStyle()?.apply {
routeLineView.renderRouteDrawData(this, value)
}
}
viewportDataSource.onRouteChanged(routeUpdateResult.navigationRoutes.first())
viewportDataSource.evaluate()
} else {
routeLineApi.clearRouteLine { value ->
mapView.getMapboxMap().getStyle()?.let {
routeLineView.renderClearRouteLineValue(it, value)
}
}
viewportDataSource.clearRouteData()
viewportDataSource.evaluate()
}
}
The issue seems to be related to the route line not being properly updated or rendered when switching screens. I need guidance on how to ensure consistent route visualization across screen transitions in the Automotive app. Is there a recommended approach to maintain route drawing state or a solution to this intermittent issue?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the screen-switching lifecycle around mapView, routeLineApi, and routeLineView, then follow the OnIndicatorPositionChangedListener, RouteProgressObserver, and RoutesObserver callbacks. Reproduce navigation with the provided route-building code and compare route rendering on both screens. Done means the route remains visible and reflects navigation state after switching screens.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100