Quickstart

The Routing module provides tools to integrate the TomTom Routing API into an Android application. It is used to calculate a route between an origin and a destination, using a range of options and taking traffic into account. Read more about TomTom’s Routing parameters .

Once planned, routes can be displayed on the map or used for turn-by-turn navigation.

Project setup

Configure the project as described in the Project setup guide .

Then, add the following dependencies to the build.gradle.kts file of your application module and synchronize the project.

implementation("com.tomtom.sdk.routing:route-planner:2.1.2")

After synchronizing the project, you can create a RoutePlanner . It is the entry point for performing routing requests. The RoutePlanner object is created through the initialization surface.

val sdkConfiguration = buildSdkConfiguration(
context = applicationContext,
apiKey = "YOUR_TOMTOM_API_KEY",
)
TomTomSdk.initialize(
context = applicationContext,
sdkConfiguration = sdkConfiguration,
)
val routePlanner = TomTomSdk.createRoutePlanner()

Making routing calls

The routing call is done asynchronously. The call requires the RoutePlanningCallback to be provided as a parameter to the request. If the call is successful, the callback’s onSuccess(result: RoutePlanningResponse) method is triggered with the routing result. Additionally, the onRoutePlanned(route: Route) method is invoked for each planned route, including the primary route. This method is useful when requesting a route with path alternatives. If a failure occurred, it is provided by the callback’s onFailure(failure: RoutingFailure) method.

val amsterdam = GeoPoint(52.377956, 4.897070)
val rotterdam = GeoPoint(51.926517, 4.462456)
val itinerary = Itinerary(origin = amsterdam, destination = rotterdam)
val routePlanningOptions = buildRoutePlanningOptions(itinerary = itinerary)
val routePlanningCallback = object : RoutePlanningCallback {
override fun onSuccess(result: RoutePlanningResponse) {
// YOUR CODE GOES HERE
}
override fun onFailure(failure: RoutingFailure) {
// YOUR CODE GOES HERE
}
override fun onRoutePlanned(route: Route) {
// YOUR CODE GOES HERE
}
}
val cancellable = routePlanner.planRoute(routePlanningOptions, routePlanningCallback)

Route with alternatives

Next steps

Since you have learned the basics of routing, here are recommendations for the next steps: