THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

Map events

Implement any action you need to be triggered on one of the following map events:

  • Panning
  • Single click
  • Double click
  • Long click
  • Map rotate
  • Camera movement

Sample use case: In your app, users invoke one behavior with a single press and another with a long press.

Use the following code snippets in your app to catch map events. In this example, the action is simply to display a toast with latitude and longitude on each map event. Of course, you can implement other cool features instead.

If you want to receive callbacks after a map is clicked, long-clicked, double-clicked or panned, then you need to define your own TomtomMapCallback listeners:

1TomtomMapCallback.OnMapClickListener onMapClickListener =
2 latLng -> displayMessage(R.string.menu_events_on_map_click, latLng)
3
4TomtomMapCallback.OnMapLongClickListener onMapLongClickListener =
5 latLng -> displayMessage(R.string.menu_events_on_map_long_click, latLng);
6
7TomtomMapCallback.OnMapDoubleClickListener onMapDoubleClickListener =
8 latLng -> displayMessage(R.string.menu_events_on_map_double_click, latLng);
9
10TomtomMapCallback.OnMapPanningListener onMapPanningListener = new TomtomMapCallback.OnMapPanningListener() {
11 @Override
12 public void onMapPanningStarted() {
13 displayMessage(R.string.menu_events_on_map_panning_started, tomtomMap.getCenterOfMap());
14 }
15
16 @Override
17 public void onMapPanningOngoing() {
18 displayMessage(R.string.menu_events_on_map_panning_ongoing, tomtomMap.getCenterOfMap());
19 }
20
21 @Override
22 public void onMapPanningEnded() {
23 displayMessage(R.string.menu_events_on_map_panning_ended, tomtomMap.getCenterOfMap());
24 }
25};
1val showMessageWhenOnMapClick: TomtomMapCallback.OnMapClickListener =
2 TomtomMapCallback.OnMapClickListener { latLng -> displayMessage(SINGLE_PRESS_TITLE, latLng) }
3
4val showMessageWhenOnMapLongClick: TomtomMapCallback.OnMapLongClickListener =
5 TomtomMapCallback.OnMapLongClickListener { latLng -> displayMessage(LONG_CLICK_TITLE, latLng) }
6
7val showMessageWhenOnMapDoubleClick: TomtomMapCallback.OnMapDoubleClickListener =
8 TomtomMapCallback.OnMapDoubleClickListener { latLng -> displayMessage(DOUBLE_CLICK_TITLE, latLng) }
9
10val showMessageWhenMapPanningOccurs: TomtomMapCallback.OnMapPanningListener =
11 object : TomtomMapCallback.OnMapPanningListener {
12 override fun onMapPanningStarted() {
13 displayMessage(MAP_PANNING_STARTED_TITLE)
14 }
15
16 override fun onMapPanningOngoing() {
17 displayMessage(MAP_PANNING_ONGOING_TITLE)
18 }
19
20 override fun onMapPanningEnded() {
21 displayMessage(MAP_PANNING_ENDED_TITLE)
22 }
23 }

Then set them to your TomtomMap instance:

1tomtomMap.addOnMapClickListener(onMapClickListener);
2tomtomMap.addOnMapLongClickListener(onMapLongClickListener);
3tomtomMap.addOnMapDoubleClickListener(onMapDoubleClickListener);
4tomtomMap.addOnMapPanningListener(onMapPanningListener);
1tomtomMap.addOnMapClickListener(showMessageWhenOnMapClick)
2tomtomMap.addOnMapLongClickListener(showMessageWhenOnMapLongClick)
3tomtomMap.addOnMapDoubleClickListener(showMessageWhenOnMapDoubleClick)
4tomtomMap.addOnMapPanningListener(showMessageWhenMapPanningOccurs)

After callbacks are no longer required you can unregister them by calling:

1tomtomMap.removeOnMapClickListener(onMapClickListener);
2tomtomMap.removeOnMapLongClickListener(onMapLongClickListener);
3tomtomMap.removeOnMapDoubleClickListener(onMapDoubleClickListener);
4tomtomMap.removeOnMapPanningListener(onMapPanningListener);
1tomtomMap.removeOnMapClickListener(showMessageWhenOnMapClick)
2tomtomMap.removeOnMapLongClickListener(showMessageWhenOnMapLongClick)
3tomtomMap.removeOnMapDoubleClickListener(showMessageWhenOnMapDoubleClick)
4tomtomMap.removeOnMapPanningListener(showMessageWhenMapPanningOccurs)

If you want to receive information about the camera changing its position, then you need to define your own TomtomCallback listeners:

1TomtomMapCallback.OnCameraChangedListener onCameraChangedListener =
2 cameraPosition -> displayMessage(R.string.menu_events_on_camera_changed);
3
4TomtomMapCallback.OnCameraMoveStartedListener onCameraMoveStartedListener =
5 () -> displayMessage(R.string.menu_events_on_camera_move_started);
6
7TomtomMapCallback.OnCameraMoveListener onCameraMoveListener =
8 () -> displayMessage(R.string.menu_events_on_camera_move);
9
10TomtomMapCallback.OnCameraMoveFinishedListener onCameraMoveFinishedListener =
11 () -> displayMessage(R.string.menu_events_on_camera_move_finished);
12
13TomtomMapCallback.OnCameraMoveCanceledListener onCameraMoveCanceledListener =
14 () -> displayMessage(R.string.menu_events_on_camera_move_canceled);
1val onCameraChangedListener = OnCameraChangedListener {
2 displayMessage(ON_CAMERA_CHANGED_MESSAGE)
3}
4val onCameraMoveStartedListener = OnCameraMoveStartedListener {
5 displayMessage(ON_CAMERA_MOVE_STARTED_MESSAGE)
6}
7val onCameraMoveListener = OnCameraMoveListener {
8 displayMessage(ON_CAMERA_MOVE_MESSAGE)
9}
10val onCameraMoveFinishedListener = OnCameraMoveFinishedListener {
11 displayMessage(ON_CAMERA_MOVE_FINISHED_MESSAGE)
12}
13val onCameraMoveCanceledListener = OnCameraMoveCanceledListener {
14 displayMessage(ON_CAMERA_MOVE_CANCELED_MESSAGE)
15}

Then register them using your TomtomMap instance:

1tomtomMap.addOnCameraChangedListener(onCameraChangedListener);
2tomtomMap.addOnCameraMoveStartedListener(onCameraMoveStartedListener);
3tomtomMap.addOnCameraMoveListener(onCameraMoveListener);
4tomtomMap.addOnCameraMoveFinishedListener(onCameraMoveFinishedListener);
5tomtomMap.addOnCameraMoveCanceledListener(onCameraMoveCanceledListener);
1tomtomMap.addOnCameraChangedListener(onCameraChangedListener)
2tomtomMap.addOnCameraMoveStartedListener(onCameraMoveStartedListener)
3tomtomMap.addOnCameraMoveListener(onCameraMoveListener)
4tomtomMap.addOnCameraMoveFinishedListener(onCameraMoveFinishedListener)
5tomtomMap.addOnCameraMoveCanceledListener(onCameraMoveCanceledListener)

After callbacks are no longer required you can unregister them by calling:

1tomtomMap.removeOnCameraChangedListener(onCameraChangedListener);
2tomtomMap.removeOnCameraMoveStartedListener(onCameraMoveStartedListener);
3tomtomMap.removeOnCameraMoveListener(onCameraMoveListener);
4tomtomMap.removeOnCameraMoveFinishedListener(onCameraMoveFinishedListener);
5tomtomMap.removeOnCameraMoveCanceledListener(onCameraMoveCanceledListener);
1tomtomMap.removeOnCameraChangedListener(onCameraChangedListener)
2tomtomMap.removeOnCameraMoveStartedListener(onCameraMoveStartedListener)
3tomtomMap.removeOnCameraMoveListener(onCameraMoveListener)
4tomtomMap.removeOnCameraMoveFinishedListener(onCameraMoveFinishedListener)
5tomtomMap.removeOnCameraMoveCanceledListener(onCameraMoveCanceledListener)

In this example you will see a Toast with the latitude and longitude of a point that was clicked on the map, but you can utilize this information in your own manner.

image

Receive callbacks after the map is clicked.

image

Receive callbacks after the map is long clicked.

image

Receive callbacks after the map panning.

Enable and disable gestures

You can disable gestures such as zooming, panning, and rotating in your application by passing the GesturesConfiguration object to tomtomMap: By default all gestures are enabled.

Disable zooming gesture

1tomtomMap.updateGesturesConfiguration(
2 new GesturesConfiguration.Builder()
3 .zoomEnabled(false)
4 .build()
5);
1tomtomMap.updateGesturesConfiguration(
2 GesturesConfiguration.Builder()
3 .zoomEnabled(false)
4 .build()
5)

Disable the rotating gesture

1tomtomMap.updateGesturesConfiguration(
2 new GesturesConfiguration.Builder()
3 .rotationEnabled(false)
4 .build()
5);
1tomtomMap.updateGesturesConfiguration(
2 GesturesConfiguration.Builder()
3 .rotationEnabled(false)
4 .build()
5)

Disable the tilting gesture

1tomtomMap.updateGesturesConfiguration(
2 new GesturesConfiguration.Builder()
3 .tiltEnabled(false)
4 .build()
5);
1tomtomMap.updateGesturesConfiguration(
2 GesturesConfiguration.Builder()
3 .tiltEnabled(false)
4 .build()
5)

Disable the panning gesture

1tomtomMap.updateGesturesConfiguration(
2 new GesturesConfiguration.Builder()
3 .panningEnabled(false)
4 .build()
5);
1tomtomMap.updateGesturesConfiguration(
2 GesturesConfiguration.Builder()
3 .panningEnabled(false)
4 .build()
5)

You can turn off more than one gesture by setting up the mask on properties as shown in the following code snippets:

1tomtomMap.updateGesturesConfiguration(
2 new GesturesConfiguration.Builder()
3 .rotationEnabled(false)
4 .panningEnabled(false)
5 .build()
6);
1tomtomMap.updateGesturesConfiguration(
2 GesturesConfiguration.Builder()
3 .rotationEnabled(false)
4 .panningEnabled(false)
5 .build()
6)

If you want to enable gestures, pass the GesturesConfiguration object to the tomtomMap object as shown in the following code snippets:

1tomtomMap.updateGesturesConfiguration(
2 new GesturesConfiguration.Builder()
3 .rotationEnabled(true)
4 .panningEnabled(true)
5 .zoomEnabled(true)
6 .tiltEnabled(true)
7 .build()
8);
1tomtomMap.updateGesturesConfiguration(
2 GesturesConfiguration.Builder()
3 .rotationEnabled(true)
4 .panningEnabled(true)
5 .zoomEnabled(true)
6 .tiltEnabled(true)
7 .build()
8)

or even in a simpler way:

tomtomMap.updateGesturesConfiguration(new GesturesConfiguration.Builder().build());
1tomtomMap.updateGesturesConfiguration(
2 GesturesConfiguration.Builder().build()
3)