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.
1val sdkConfiguration = buildSdkConfiguration(2 context = applicationContext,3 apiKey = "YOUR_TOMTOM_API_KEY",4)5TomTomSdk.initialize(6 context = applicationContext,7 sdkConfiguration = sdkConfiguration,8)9val 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.
1val amsterdam = GeoPoint(52.377956, 4.897070)2val rotterdam = GeoPoint(51.926517, 4.462456)3val itinerary = Itinerary(origin = amsterdam, destination = rotterdam)4val routePlanningOptions = buildRoutePlanningOptions(itinerary = itinerary)56val routePlanningCallback = object : RoutePlanningCallback {7 override fun onSuccess(result: RoutePlanningResponse) {8 // YOUR CODE GOES HERE9 }1011 override fun onFailure(failure: RoutingFailure) {12 // YOUR CODE GOES HERE13 }1415 override fun onRoutePlanned(route: Route) {16 // YOUR CODE GOES HERE17 }18}1920val cancellable = routePlanner.planRoute(routePlanningOptions, routePlanningCallback)
Next steps
Since you have learned the basics of routing, here are recommendations for the next steps: