Turn by Turn Navigation

Start Navigation

To start navigation, first we need to create required navigation details. This can be done either using destination coordinates or with a trip id.

When using navigation with destination coordinate, you can also provide the route mode. By default this is CAR

val navigationData = NavigationManager.NavigationBuilder()
    .setRoutingConfig(Coordinates(lat, lng), RouteMode.TRUCK)

In case you used one of our other apis (multi routing..etc) and you want to enforce following that API’s generated route you can use a trip id that will be generated through the same API and pass it to the SDK.

There is also the extra functionality of how to handle route deviation, based on enforceRoute flag you decide what to do in case of deviation. If the flag is true a new route to navigate the user back to the planned route will be shown and then the navigation will carry from there, if the flag is false then a new optimized route to the end destination will be created and the original planned route will be discarded. By default the flag is false.

val navigationData = NavigationManager.NavigationBuilder()
    .setRoutingConfig(tripId, enforceRoute)

Pass the navigation details to the NaigationFragment and use this fragment to start navigation.

val navigationFragment = NavigationFragment().apply {
    arguments = Bundle().apply {
        putParcelable(CLIENT_ARG_NAME, navigationData)

Customise the UI

You can also customise the pre-build UI component used to display the changing navigation information using setThemeConfig() in the NavigationBuilder.

val themeConfig = ThemeConfig(
    ContextCompat.getColor(requireContext(), R.color.col_thunderbird_red),
    ContextCompat.getColor(requireContext(), R.color.col_ahoy_blue_light),
    ContextCompat.getColor(requireContext(), android.R.color.black),
    ContextCompat.getColor(requireContext(), R.color.col_mariner_blue),
    ContextCompat.getColor(requireContext(), R.color.white)

val navigationData = NavigationManager.NavigationBuilder()
    .setDestinationInfo(lat, lng, "Destination Name")

Get update on reaching the destination

Do the following to get notified on reaching the destination,

navigationFragment.setDestinationReachedListener {
      Toast.makeText(requireContext(), "You have arrived",Toast.LENGTH_LONG).show()

Get update on close

Do the following to get notified when user clicks the close icon,

navigationFragment.setNavigationClosedListener {

Get callback on navigation errors

To get callbacks whenever there is an error with navigation, do the following. Read more about error handling here

navigationFragment.setOnNavigationErrorListener {
    Toast.makeText(requireContext(), it.message, Toast.LENGTH_SHORT).show()