mapbox / mapbox/mapbox-navigation-android

Add route selection by index

Open
#4,980 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

jira-sync-complete v3.x
Dominant language
Kotlin
Stars
651
Forks
321
PR merge metrics
No merged PRs in 30d

Description

**Mapbox Navigation SDK version:** 2.1.0

EDIT: grammar

Follow up work from https://github.com/mapbox/mapbox-navigation-android/pull/4892. Anticipating this issue will require refactoring and testing in order to get it all just right. It is considered out of scope of the initial integration of continuous alternatives because we may not want to do this. Re-ordering the list and assuming route index zero also works.

Here is the existing way to change the route leg in MapboxNavigation
``` kotlin
fun navigateNextRouteLeg(callback: LegIndexUpdatedCallback) {
arrivalProgressObserver.navigateNextRouteLeg(callback)
}
```

So here we're proposing adding and/or changing the functions in MapboxNavigation
``` kotlin
// Adding routeIndex may be semver, since it changes the position of the setRoute arguments
fun setRoutes(routes: List, routeIndex: Int = 0, initialLegIndex: Int = 0) {

// After routes have been set, be able to change the route index with something like this.
fun setPrimaryRoute(routeIndex: Int)
fun setPrimaryRoute(route: DirectionsRoute)
```

## Ui code to select a route

[Before](https://github.com/mapbox/mapbox-navigation-android/blob/ac985d5298f3b9dae22a8dae2eb74a5366ed7c1e/qa-test-app/src/main/java/com/mapbox/navigation/qa_test_app/view/AlternativeRouteActivity.kt#L273-L293)
``` kotlin
private val mapClickListener = OnMapClickListener { point ->
CoroutineScope(Dispatchers.Main).launch {
val result = routeLineApi.findClosestRoute(
point,
binding.mapView.getMapboxMap(),
routeClickPadding
)

val routeFound = result.value?.route
if (routeFound != null && routeFound != routeLineApi.getPrimaryRoute()) {
val reOrderedRoutes = routeLineApi.getRoutes()
.filter { it != routeFound }
.toMutableList()
.also {
it.add(0, routeFound)
}
mapboxNavigation.setRoutes(reOrderedRoutes)
}
}
false
}
```

After
``` kotlin
private val mapClickListener = OnMapClickListener { point ->
CoroutineScope(Dispatchers.Main).launch {
val result = routeLineApi.findClosestRoute(
point,
binding.mapView.getMapboxMap(),
routeClickPadding
)

result.value?.route?.let { mapboxNavigation.setPrimaryRoute(it)
}
false
}
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the MapboxNavigation entry point and the existing navigateNextRouteLeg and setRoutes APIs. Compare the current AlternativeRouteActivity implementation with the proposed setPrimaryRoute usage to understand route selection behavior. Done means supporting primary-route selection by index or DirectionsRoute while preserving route and leg handling, with refactoring and tests covering the new behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
api, mobile
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.