Skip to content

Can’t start turn-by-turn navigation within custom NavigationViewActivity/NavigationViewFragment #1524

@JaninaMattes

Description

@JaninaMattes

Hey, I implemented the custom NavigationActivity following part of the example in the Mapbox documentation and can show the navigation UI as map so far but can't start the navigation itself nor show the user’s location. The same problem exists when implementing it via a NavigationFragment. How can I pass the missing information when I call my NavigationActivity/NavigationFragment from my MainActivity and start the navigation correctly? Thanks a lot for any help!

I create the directionsRoute and call navigationView.startNavigation(options) with NavigationViewOptions.builder() like this:

fun onNavigationReady(isRunning: Boolean) {
...
calculateRoute(origin, destination)
} 
private fun calculateRoute(origin: Point , destination: Point) {
       NavigationRoute.builder(this.context)
               .accessToken(Mapbox.getAccessToken()!!)
               .origin(origin)
               .destination(destination)
               .build()
               .getRoute( object : Callback<DirectionsResponse> {
                   // Send request to Direction API
                   override fun onFailure(call: Call<DirectionsResponse>? , t: Throwable?) {
                   }
                   override fun onResponse(call: Call<DirectionsResponse>? ,
                                           response: Response<DirectionsResponse>?) {
                       if (response?.body() == null || response.body()?.routes()?.size!! < 1) {
                           return
                       }
                       directionsRoute = response.body()!!.routes()[0]
                       startNavigation()
                   }
               })
   }

private fun startNavigation() {
       if (directionsRoute == null) return
       val options = NavigationViewOptions.builder()
               .directionsRoute(directionsRoute)
               .shouldSimulateRoute(true)
               .navigationListener(this)
               .build()

       navigationView.startNavigation(options)
   }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions