THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

Zooming the route

Zooming in and out are used to navigate through map areas that are too large or too small to be conveniently displayed within a single window. While following the chevron, zooming alters the map scale because it changes the proportion of the workspace shown in each window.

Sample use case: You are a taxi driver navigating through the city of Łódź, and thanks to the zoom level adjusted to the velocity of your car you see a convenient map area for you to move.

Use the following code snippets to try this in your app:

1fun setupLocationUpdateListener(tomtomMap: TomtomMap) {
2 tomtomMap.addLocationUpdateListener { location ->
3 updateZoomLevelBaseOnNewLocation(tomtomMap, location)
4 }
5}
6
7private fun updateZoomLevelBaseOnNewLocation(tomtomMap: TomtomMap, location: Location) {
8 val zoomLevel = when (location.speed) {
9 in SMALL_SPEED_RANGE_IN_KMH -> SMALL_SPEED_ZOOM_LEVEL
10 in MEDIUM_SPEED_RANGE_IN_KMH -> MEDIUM_SPEED_ZOOM_LEVEL
11 in GREATER_SPEED_RANGE_IN_KMH -> GREATER_SPEED_ZOOM_LEVEL
12 in BIG_SPEED_RANGE_IN_KMH -> BIG_SPEED_ZOOM_LEVEL
13 in HUGE_SPEED_RANGE_IN_KMH -> HUGE_SPEED_ZOOM_LEVEL
14 else -> tomtomMap.zoomLevel
15 }
16 if (tomtomMap.zoomLevel != zoomLevel) {
17 setCameraPosition(tomtomMap, zoomLevel = zoomLevel)
18 }
19}
20
21private fun setCameraPosition(tomtomMap: TomtomMap, zoomLevel: Double) {
22 if (!isZooming) {
23 isZooming = true
24 tomtomMap.centerOn(
25 CameraPosition.builder()
26 .zoom(zoomLevel)
27 .animationDuration(ZOOM_CHANGE_ANIMATION_MILLIS)
28 .build(),
29 onMapCenteredCallback
30 )
31 }
32}
33
34private val onMapCenteredCallback = object : OnMapCenteredCallback {
35 override fun onFinish() {
36 isZooming = false
37 }
38
39 override fun onCancel() {
40 isZooming = false
41 }
42}

Lookup for the constants used in the sample code:

1private const val EXAMPLE_START_ZOOM_LEVEL = 19.0
2private const val ZOOM_CHANGE_ANIMATION_MILLIS = 300
3private const val SMALL_SPEED_ZOOM_LEVEL = 19.0
4private const val MEDIUM_SPEED_ZOOM_LEVEL = 18.0
5private const val GREATER_SPEED_ZOOM_LEVEL = 17.0
6private const val BIG_SPEED_ZOOM_LEVEL = 16.0
7private const val HUGE_SPEED_ZOOM_LEVEL = 14.0
8private val SMALL_SPEED_RANGE_IN_KMH = 0.0..10.0
9private val MEDIUM_SPEED_RANGE_IN_KMH = 10.0..20.0
10private val GREATER_SPEED_RANGE_IN_KMH = 20.0..40.0
11private val BIG_SPEED_RANGE_IN_KMH = 40.0..70.0
12private val HUGE_SPEED_RANGE_IN_KMH = 70.0..120.0

Screen shots presenting how the programmatic zooming functionality works:

Driving ZoomLevel