mapbox / mapbox/mapbox-navigation-android
Drop-In Navigation Not Working Correctly.
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:**
```
implementation "com.mapbox.navigation:ui-dropin:2.11.0"
implementation "com.mapbox.navigation:android:2.10.1"
```
Hello All,
I've been using mapbox for many years now, but It's come to the point I'm required to upgrade to the latest version, I'm currently in the process of developing my application and making the changes to the new version of mapbox.
I'm coming across an issue with the drop-in navigation, when the application starts for the very first time and I provide a MapMatching Navigation Route the app runs fine and the navigation route works, however if I end the navigation or go back from this screen and attempt to run the navigation again the Navigation doesn't work, The route plots on the map but the instructions don't show, the camera doesn't move to the start of the route and the guidance does not start.
I have the following to launch the navigation.
```
...
binding.navigationView.api.routeReplayEnabled(true)
binding.navigationView.api.startActiveGuidance(listOf(this))
...
```
Our routes contain approx. 3000-5000 coordinates so we are required to split this out into separate request, and when the first section of the route is about to end we start the next request and so on, but I'm unable to start the next section of the navigation.
**MapMatching Request**
```
// Limit Route Coordinates For MAPMATCHING_LIMIT
// If Points Left are Less Than LIMIT Return Remaining.
val subPoints: List
if (points.size > MAPMATCHING_LIMIT) {
subPoints = points.subList(0, MAPMATCHING_LIMIT)
} else {
subPoints = points
}
// MAP MATCHING REQUEST
val mapboxMapMatchingRequest = MapboxMapMatching.builder()
.accessToken(getString(R.string.mapbox_access_token))
.coordinates(subPoints)
.steps(true)
.tidy(true)
.waypointIndices(0, subPoints.size - 1)
.language(Locale.UK.language)
.voiceInstructions(true)
.bannerInstructions(true)
.profile(DirectionsCriteria.PROFILE_DRIVING)
.build()
```
**MapMatching Response**
```
mapboxMapMatchingRequest.enqueueCall(object : Callback {
override fun onResponse(
call: Call,
response: Response
) {
if (response.isSuccessful) {
Log.d(TAG, "Map Matching Successful.")
response.body()?.matchings()?.let { matchingList ->
Log.d(TAG, "Matchings Count: " + matchingList.size)
matchingList[0].toDirectionRoute().toNavigationRoute(
RouterOrigin.Custom()
).apply {
val bSimulate: Boolean = shouldSimulateRoute()
Log.d(TAG, "Enable Route Simulate? - $bSimulate" )
binding.navigationView.api.routeReplayEnabled(bSimulate)
Log.d(TAG, "Start Guidance for Route")
binding.navigationView.api.startActiveGuidance(listOf(this))
}
}
}
}
override fun onFailure(call: Call, t: Throwable) {
Log.d(TAG, "Map Matching Failed. " + t.message)
Toast.makeText(
this@ActivityNav,
"Map Matching Failed. " + t.message,
Toast.LENGTH_LONG
).show()
}
})
```
**Location Observer**
```
private val locationObserver = object : LocationObserver {
override fun onNewLocationMatcherResult(locationMatcherResult: LocationMatcherResult) {
lastLocation = locationMatcherResult.enhancedLocation
}
override fun onNewRawLocation(rawLocation: Location) {
// no impl
}
}
```
**OnCreate**
```
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d(TAG, "onCreate()")
binding = ActivityNavBinding.inflate(layoutInflater)
setContentView(binding.root)
// Set to false if you want to handle map long click listener in the app
binding.navigationView.customizeViewOptions {
enableMapLongClickIntercept = false
}
//binding.navigationView.registerMapObserver(mapViewObserver)
MapboxNavigationApp.current()?.registerLocationObserver(locationObserver)
// Start Navigation Automatically.
requestRoute(getCoordinatesData())
}
```
**OnDestroy**
```
override fun onDestroy() {
super.onDestroy()
Log.d(TAG, "onDestroy()")
MapboxNavigationApp.current()?.unregisterArrivalObserver(arrivalObserver)
MapboxNavigationApp.current()?.unregisterRouteProgressObserver(routeProgressObserver)
//binding.navigationView.unregisterMapObserver(mapViewObserver)
MapboxNavigationApp.current()?.unregisterLocationObserver(locationObserver)
/*
if (MapboxNavigationApp.current()?.getTripSessionState() == TripSessionState.STARTED){
MapboxNavigationApp.current()?.stopTripSession()
}
*/
}
```
**Layout**
```
```
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 with the NavigationView lifecycle in onCreate and onDestroy, then trace the calls to routeReplayEnabled and startActiveGuidance in the provided Map Matching response. Reproduce the first and second navigation attempts, including the transition to the next route section; done means guidance, instructions, and camera movement work on subsequent starts.
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
- 32/100