Routes

VERSION 1.0.0

The Map Display module allows you to handle route planning and driving actions on the map. This guide covers how to draw a Route, show the progress along it, and track the user’s location during the trip.

If you’re looking for route planning, see the Routing guide.

Adding a route

To show a Route on the map, you need to call the TomTomMap.addRoute(RouteOptions) method. To configure its shape and appearance, use the RouteOptions class. Drawing a route on the map requires a list with coordinates of the route points. You can also define its appearance by setting its color, width, and the visibility of departure and destination markers. Route width can be defined as a single value (which will be the same for all zoom levels), or different route widths can be set for different zoom levels. The width will be then interpolated for all the zoom levels in between. RouteOptions also supports specific routing features such as showing the user’s progress, or providing a list of instructions along the route.

1val routeOptions = RouteOptions(
2 geometry = listOf(
3 GeoPoint(52.377956, 4.897070),
4 GeoPoint(51.377956, 4.997070),
5 GeoPoint(50.377956, 5.897070),
6 GeoPoint(52.377956, 5.897070)
7 ),
8 color = Color.BLUE,
9 outlineWidth = 3.0,
10 widths = listOf(WidthByZoom(5.0)),
11 progress = Distance.meters(1000.0),
12 instructions = listOf(
13 Instruction(
14 routeOffset = Distance.meters(1000.0),
15 combineWithNext = false
16 ),
17 Instruction(
18 routeOffset = Distance.meters(2000.0),
19 combineWithNext = true
20 ),
21 Instruction(routeOffset = Distance.meters(3000.0))
22 ),
23 tag = "Extra information about the route",
24 departureMarkerVisible = true,
25 destinationMarkerVisible = true
26)
27val route = tomTomMap.addRoute(routeOptions)
Adding a route

You can pass the optional instructions parameter to show arrows for each maneuver on route line. This also enables automatic zoom and tilt changes when following a chevron.

When a route is added to the map, a Route object is returned. Use the object to retrieve information about the route and change its color, progress and instructions. The Route can also be moved to the top layer using the Route.bringToFront() method, or removed using Route.remove().

All routes added to the map can be removed with a single method, TomTomMap.removeRoutes(), called on the TomTomMap object.

tomTomMap.removeRoutes()

To show an overview of the route, update the camera to fit all the route points. Padding can also be added (optional).

tomTomMap.zoomToRoutes(padding = 100)

OnRouteClickListener

You can use a listener to listen for click events on Route objects. Add the RouteClickListener to the map to report when any Route was clicked. The selected Route is provided as a parameter for the RouteClickListener.onRouteClick(Route) method.

val routeClickListener = RouteClickListener { /* YOUR CODE GOES HERE */ }
tomTomMap.addRouteClickListener(routeClickListener)

You can remove the RouteClickListener listener if it is no longer needed.

tomTomMap.removeRouteClickListener(routeClickListener)

Updating route progress

The progress made along the Route can be indicated on the drawn map. The traveled part of the route is colored with the outline color. See the example below.

Route progress

The progress can be updated by operating on the Route object returned during drawing. Its value is expressed in meters. In the example below, the map will show that 2km have already been traveled.

route.progress = Distance.meters(2000.0)

CameraTrackingMode

The Map Display module allows you to set how the camera tracks the user locations to suit different interaction modes. Do this by setting CameraTrackingMode to the TomTomMap instance. There are five options for tracking mode:

  • None - The camera does not track the user’s location. This is the default setting and is mainly used to show the user’s location on the map.
  • FollowNorthUp - The camera follows the user’s location, but its tilt and zoom do not change.
  • FollowRouteDirection - The camera follows the user’s location and heading to best present the route. Camera properties like tilt and zoom may be adjusted to better display the route and its guidance instructions.
  • FollowDirection - The camera follows the user’s location and heading to position the camera in the heading direction. Camera is always following from the top (the tilt is set to 0 degrees).
  • FollowOverview - The camera tries to fit the routes in the current view, by changing the zoom level and other camera properties.

The last three modes are mainly used in navigation applications.

To apply a given tracking mode, set cameraTrackingMode:

tomTomMap.cameraTrackingMode = CameraTrackingMode.FollowRouteDirection

To check what tracking mode is currently set:

val cameraTrackingMode = tomTomMap.cameraTrackingMode

Instructions

The Route added to the map can also show the location and type of the maneuvers the driver must perform to follow it. These maneuvers are indicated with arrows displayed on the route (see the image below).

Route instruction

The instructions for the maneuvers can be provided as a parameter to RouteOptions class while adding a route. You can also update them during runtime by setting the Route.instructions property.

Note that the Route instance is returned when RouteOptions is added to the map.

An Instruction requires the distance from the start of the route to the instruction point in meters. You can also specify whether the arrow can be merged with the next one and define its length.

1route.instructions = listOf(
2 Instruction(
3 routeOffset = Distance.meters(1000.0),
4 length = Distance.meters(40.0),
5 combineWithNext = true
6 ),
7 Instruction(
8 routeOffset = Distance.meters(1100.0),
9 length = Distance.meters(40.0),
10 combineWithNext = false
11 )
12)

Next steps

Since you have learned how to work with routes on the map, here are recommendations for the next steps: