Sorry, you need to enable JavaScript to visit this website.

Map events

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:

_

TomtomMapCallback.OnMapClickListener onMapClickListener =
        latLng -> displayMessage(R.string.menu_events_on_map_click, latLng);

TomtomMapCallback.OnMapLongClickListener onMapLongClickListener =
        latLng -> displayMessage(R.string.menu_events_on_map_long_click, latLng);

TomtomMapCallback.OnMapDoubleClickListener onMapDoubleClickListener =
        latLng -> displayMessage(R.string.menu_events_on_map_double_click, latLng);

TomtomMapCallback.OnMapPanningListener onMapPanningListener = new TomtomMapCallback.OnMapPanningListener() {
    @Override
    public void onMapPanningStarted() {
        displayMessage(R.string.menu_events_on_map_panning_started, tomtomMap.getCenterOfMap());
    }

    @Override
    public void onMapPanningOngoing() {
        displayMessage(R.string.menu_events_on_map_panning_ongoing, tomtomMap.getCenterOfMap());
    }

    @Override
    public void onMapPanningEnded() {
        displayMessage(R.string.menu_events_on_map_panning_ended, tomtomMap.getCenterOfMap());
    }
};
val showMessageWhenOnMapClick: TomtomMapCallback.OnMapClickListener =
    TomtomMapCallback.OnMapClickListener { latLng -> displayMessage(SINGLE_PRESS_TITLE, latLng) }

val showMessageWhenOnMapLongClick: TomtomMapCallback.OnMapLongClickListener =
    TomtomMapCallback.OnMapLongClickListener { latLng -> displayMessage(LONG_CLICK_TITLE, latLng) }

val showMessageWhenOnMapDoubleClick: TomtomMapCallback.OnMapDoubleClickListener =
    TomtomMapCallback.OnMapDoubleClickListener { latLng -> displayMessage(DOUBLE_CLICK_TITLE, latLng) }

val showMessageWhenMapPanningOccurs: TomtomMapCallback.OnMapPanningListener =
    object : TomtomMapCallback.OnMapPanningListener {
        override fun onMapPanningStarted() {
            displayMessage(MAP_PANNING_STARTED_TITLE)
        }

        override fun onMapPanningOngoing() {
            displayMessage(MAP_PANNING_ONGOING_TITLE)
        }

        override fun onMapPanningEnded() {
            displayMessage(MAP_PANNING_ENDED_TITLE)
        }
    }

 

Then set them to your TomtomMap instance:

_

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

 

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

_

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

 

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

_

TomtomMapCallback.OnCameraChangedListener onCameraChangedListener =
        cameraPosition -> displayMessage(R.string.menu_events_on_camera_changed);

TomtomMapCallback.OnCameraMoveStartedListener onCameraMoveStartedListener =
        () -> displayMessage(R.string.menu_events_on_camera_move_started);

TomtomMapCallback.OnCameraMoveListener onCameraMoveListener =
        () -> displayMessage(R.string.menu_events_on_camera_move);

TomtomMapCallback.OnCameraMoveFinishedListener onCameraMoveFinishedListener =
        () -> displayMessage(R.string.menu_events_on_camera_move_finished);

TomtomMapCallback.OnCameraMoveCanceledListener onCameraMoveCanceledListener =
        () -> displayMessage(R.string.menu_events_on_camera_move_canceled);
val onCameraChangedListener = OnCameraChangedListener {
    displayMessage(ON_CAMERA_CHANGED_MESSAGE)
}
val onCameraMoveStartedListener = OnCameraMoveStartedListener {
    displayMessage(ON_CAMERA_MOVE_STARTED_MESSAGE)
}
val onCameraMoveListener = OnCameraMoveListener {
    displayMessage(ON_CAMERA_MOVE_MESSAGE)
}
val onCameraMoveFinishedListener = OnCameraMoveFinishedListener {
    displayMessage(ON_CAMERA_MOVE_FINISHED_MESSAGE)
}
val onCameraMoveCanceledListener = OnCameraMoveCanceledListener {
    displayMessage(ON_CAMERA_MOVE_CANCELED_MESSAGE)
}

 

Then register them using your TomtomMap instance:

_

tomtomMap.addOnCameraChangedListener(onCameraChangedListener);
tomtomMap.addOnCameraMoveStartedListener(onCameraMoveStartedListener);
tomtomMap.addOnCameraMoveListener(onCameraMoveListener);
tomtomMap.addOnCameraMoveFinishedListener(onCameraMoveFinishedListener);
tomtomMap.addOnCameraMoveCanceledListener(onCameraMoveCanceledListener);
tomtomMap.addOnCameraChangedListener(onCameraChangedListener)
tomtomMap.addOnCameraMoveStartedListener(onCameraMoveStartedListener)
tomtomMap.addOnCameraMoveListener(onCameraMoveListener)
tomtomMap.addOnCameraMoveFinishedListener(onCameraMoveFinishedListener)
tomtomMap.addOnCameraMoveCanceledListener(onCameraMoveCanceledListener)

 

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

_

tomtomMap.removeOnCameraChangedListener(onCameraChangedListener);
tomtomMap.removeOnCameraMoveStartedListener(onCameraMoveStartedListener);
tomtomMap.removeOnCameraMoveListener(onCameraMoveListener);
tomtomMap.removeOnCameraMoveFinishedListener(onCameraMoveFinishedListener);
tomtomMap.removeOnCameraMoveCanceledListener(onCameraMoveCanceledListener);
tomtomMap.removeOnCameraChangedListener(onCameraChangedListener)
tomtomMap.removeOnCameraMoveStartedListener(onCameraMoveStartedListener)
tomtomMap.removeOnCameraMoveListener(onCameraMoveListener)
tomtomMap.removeOnCameraMoveFinishedListener(onCameraMoveFinishedListener)
tomtomMap.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

_

tomtomMap.updateGesturesConfiguration(
        new GesturesConfiguration.Builder()
                .zoomEnabled(false)
                .build()
);
tomtomMap.updateGesturesConfiguration(
    GesturesConfiguration.Builder()
        .zoomEnabled(false)
        .build()
)

 

Disable the rotating gesture

_

tomtomMap.updateGesturesConfiguration(
        new GesturesConfiguration.Builder()
                .rotationEnabled(false)
                .build()
);
tomtomMap.updateGesturesConfiguration(
    GesturesConfiguration.Builder()
        .rotationEnabled(false)
        .build()
)

 

Disable the tilting gesture

_

tomtomMap.updateGesturesConfiguration(
        new GesturesConfiguration.Builder()
                .tiltEnabled(false)
                .build()
);
tomtomMap.updateGesturesConfiguration(
    GesturesConfiguration.Builder()
        .tiltEnabled(false)
        .build()
)

 

Disable the panning gesture

_

tomtomMap.updateGesturesConfiguration(
        new GesturesConfiguration.Builder()
                .panningEnabled(false)
                .build()
);
tomtomMap.updateGesturesConfiguration(
    GesturesConfiguration.Builder()
        .panningEnabled(false)
        .build()
)

 

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

_

tomtomMap.updateGesturesConfiguration(
        new GesturesConfiguration.Builder()
                .rotationEnabled(false)
                .panningEnabled(false)
                .build()
);
tomtomMap.updateGesturesConfiguration(
    GesturesConfiguration.Builder()
        .rotationEnabled(false)
        .panningEnabled(false)
        .build()
)

 

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

_

tomtomMap.updateGesturesConfiguration(
        new GesturesConfiguration.Builder()
                .rotationEnabled(true)
                .panningEnabled(true)
                .zoomEnabled(true)
                .tiltEnabled(true)
                .build()
);
tomtomMap.updateGesturesConfiguration(
    GesturesConfiguration.Builder()
        .rotationEnabled(true)
        .panningEnabled(true)
        .zoomEnabled(true)
        .tiltEnabled(true)
        .build()
)

 

or even in a simpler way:

_

tomtomMap.updateGesturesConfiguration(new GesturesConfiguration.Builder().build());
tomtomMap.updateGesturesConfiguration(
    GesturesConfiguration.Builder().build()
)