mapbox / mapbox/mapbox-navigation-android
Navigation on mapmatched route
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 651
- Forks
- 321
- PR merge metrics
- No merged PRs in 30d
Description
Hi there,
I got stuck implementing mapmatching and then navigating on the route. Basically mapmatching works fine, I got back the correct points. But when giving the points to the navigation engine, it crashes. Do you have any idea what I might do wrong?
Here is the method for fetching routes based on a list of coordinates:
```
private fun fetchRoute(coordinates: List) {
print("MapMatching request with ${coordinates.size} coordinates.")
val mapMatching = Mapbox.getAccessToken()?.let {
MapboxMapMatching.builder()
.accessToken(it)
.coordinates(coordinates)
.bannerInstructions(true)
.voiceInstructions(true)
.profile(DirectionsCriteria.PROFILE_CYCLING)
.build()
.enqueueCall(object : Callback {
override fun onResponse(call: Call, response: Response) {
val directionsResponse = response.body()
if (directionsResponse != null) {
if (directionsResponse.matchings() != null) {
directionsResponse.matchings()?.get(0)?.toDirectionRoute()?.let { it1 ->
buildAndStartNavigation(it1)
// it1 -> navigationMapboxMap?.drawRoute(it1)
}
} else {
val message = directionsResponse.message()
sendEvent(MapBoxEvents.ROUTE_BUILD_FAILED, message!!)
finish()
}
}
}
override fun onFailure(call: Call, t: Throwable) {
sendEvent(MapBoxEvents.ROUTE_BUILD_FAILED, t.localizedMessage)
finish()
}
})
}
}
```
And then this my method I'm calling to start the navigation, and this is where it crashes when calling `navigationView?.startNavigation(options)`:
```
private fun buildAndStartNavigation(directionsRoute: DirectionsRoute) {
dropoffDialogShown = false
navigationView?.retrieveNavigationMapboxMap()?.let { navigationMap ->
if (FlutterMapboxNavigationPlugin.mapStyleUrlDay != null)
navigationMap.retrieveMap().setStyle(Style.Builder().fromUri(FlutterMapboxNavigationPlugin.mapStyleUrlDay as String))
if (FlutterMapboxNavigationPlugin.mapStyleUrlNight != null)
navigationMap.retrieveMap().setStyle(Style.Builder().fromUri(FlutterMapboxNavigationPlugin.mapStyleUrlNight as String))
this.navigationMapboxMap = navigationMap
this.navigationMapboxMap.updateLocationLayerRenderMode(RenderMode.NORMAL)
navigationView?.retrieveMapboxNavigation()?.let {
this.mapboxNavigation = it
mapboxNavigation.addOffRouteListener(this)
mapboxNavigation.addFasterRouteListener(this)
mapboxNavigation.addNavigationEventListener(this)
}
// Custom map style has been loaded and map is now ready
val options =
NavigationViewOptions.builder()
.progressChangeListener(this)
.milestoneEventListener(this)
.navigationListener(this)
.speechAnnouncementListener(this)
.bannerInstructionsListener(this)
.routeListener(this)
.directionsRoute(directionsRoute)
.shouldSimulateRoute(FlutterMapboxNavigationPlugin.simulateRoute)
.build()
navigationView?.startNavigation(options)
}
}
```
Can you please help me how I can assign the mapmatched points to the navigationView and call startNavigation on it? Thanks
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 fetchRoute and buildAndStartNavigation, focusing on the directionsResponse.matchings()?.get(0)?.toDirectionRoute() conversion and the navigationView?.startNavigation(options) call. Reproduce the crash and inspect its exception and stack trace, which are not included here. Done means identifying whether the map-matched route is accepted by the navigation view and documenting or correcting the failing integration path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100