im trying to implement the cycling profile to the navigation, i did it this way:
private fun requestRoutes(origin: Point, destination: Point) {
MapboxNavigationApp.current()!!.requestRoutes(
routeOptions = RouteOptions
.builder()
.applyDefaultNavigationOptions()
.applyLanguageAndVoiceUnitOptions(this)
.coordinatesList(listOf(origin, destination))
.alternatives(true)
.profile(DirectionsCriteria.PROFILE_CYCLING)
.build(),
callback = object : NavigationRouterCallback {
override fun onCanceled(routeOptions: RouteOptions, routerOrigin: RouterOrigin) {
// no impl
}
override fun onFailure(reasons: List<RouterFailure>, routeOptions: RouteOptions) {
// no impl
}
override fun onRoutesReady(routes: List<NavigationRoute>, routerOrigin: RouterOrigin) {
binding.navigationView.api.startActiveGuidance(routes)
// binding.navigationView.api.routeReplayEnabled(true) simulate movement
}
}
)
}
here is my onCreate function:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// set the layout
binding = MapboxActivityNavigationViewBinding.inflate(layoutInflater)
setContentView(binding.root)
// get the arg of the js
val routes = intent.getSerializableExtra("routes") as String
val arrayList = JSONArray(routes);
val originCoord = arrayList.getJSONObject(0)
val destinationCoord = arrayList.getJSONObject(1)
MapboxNavigationApp.current()?.registerLocationObserver(locationObserver)
val origin = Point.fromLngLat(originCoord.getDouble("longitude"), originCoord.getDouble("latitude"))
val destination = Point.fromLngLat(destinationCoord.getDouble("longitude"), destinationCoord.getDouble("latitude"))
origing = origin
destinationg = destination
// set the custom view binder
val navigationActivity = this
findViewById<NavigationView>(R.id.navigationView).customizeViewBinders {
infoPanelEndNavigationButtonBinder = MyinfoPanelEndNavigationButtonBinder(navigationActivity)
}
// launch the active guidance
requestRoutes(origin, destination)
}
Unfortunately when setting the profile to cycling the navigation doesnt start and it stays in free-drive mode, in other profile (driving, walking) everything works fine, is that a bug of the sdk or am i doing something wrong ?
I couldn't find any help in the documentation or on the internet
I figured it out guys, in my
requestRoutesfunction, i have those route options.turns out that the
applyDefaultNavigationOptions()is implemented this way:So i was overriding the profile since it was already set in this function. No idea why the overriding of the profile wasn't a problem for the walking and driving profile but not the cycling one but you can fix this issue by just passing the profile in the
applyDefaultNavigationOptions()function as so: