How to change the distance format of mapbox navigation SDK from imperial to metric in android apps?

Viewed 493

I have the app that uses map by Mapbox API and needs to navigate the trip of the user, so I need to show the distance format in metric. However, it defined as imperial by default in navigation SDK. To get more understanding see the following pics.

The pic 1, it shows the distance format in imperial as default.

The pic 2, it shows the distance format in metric.

To change the default format, see the below codes that I used in my app:

  • In Java
NavigationRoute.builder(v.getContext())
.accessToken(accessToken)
.origin(originPosition)
.destination(destinationPosition)
.voiceUnits(DirectionsCriteria.METRIC) //add this to change the format
.build().getRoute(new Callback<DirectionsResponse>(){
                            ...});
  • In Kotlin
NavigationRoute.builder(context)
.accessToken(accessToken)
.origin(originPosition)
.destination(destinationPosition)
.voiceUnits(DirectionsCriteria.METRIC) //add this to change the format
.build().getRoute(object : Callback<DirectionsResponse>(){
                            ...});

For more information about the navigation SDK, visit the documentation page enter link here and the used version is v0.42.6.

Enjoy your life.

0 Answers
Related