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 press

  • Double press

  • Long press

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, or panned, then you need to define your own TomtomMapCallback listeners:

_

private TomtomMapCallback.OnMapClickListener onMapClickListener =
        latLng -> displayMessage(
                R.string.menu_events_on_map_click,
                latLng.getLatitude(),
                latLng.getLongitude()
        );
private TomtomMapCallback.OnMapLongClickListener onMapLongClickListener =
        latLng -> displayMessage(
                R.string.menu_events_on_map_long_click,
                latLng.getLatitude(),
                latLng.getLongitude()
        );
private TomtomMapCallback.OnMapViewPortChanged onMapViewPortChangedListener =
        (focalLatitude, focalLongitude, zoomLevel, perspectiveRatio, yawDegrees) -> displayMessage(
                R.string.menu_events_on_map_panning,
                focalLatitude,
                focalLongitude
        );
private val showMessageWhenOnMapClick: TomtomMapCallback.OnMapClickListener = object : TomtomMapCallback.OnMapClickListener {
    override fun onMapClick(latLng: LatLng) {
        displayMessage(SINGLE_PRESS_TITLE, latLng)
    }
}

private val showMessageWhenOnMapLongClick: TomtomMapCallback.OnMapLongClickListener = object : TomtomMapCallback.OnMapLongClickListener {
    override fun onMapLongClick(latLng: LatLng) {
        displayMessage(LONG_CLICK_TITLE, latLng)
    }
}

private val showMessageWhenOnMapViewPortChanges: TomtomMapCallback.OnMapViewPortChanged = object : TomtomMapCallback.OnMapViewPortChanged {
    override fun onMapViewPortChanged(lat: Float, lon: Float, zoom: Double, perspectie: Float, yaw: Float) {
        displayMessage(VIEW_PORT_CHANGE_TITLE, LatLng(lat.toDouble(), lon.toDouble()))
    }
}

 

Then set them to your TomtomMap instance:

_

tomtomMap.addOnMapClickListener(onMapClickListener);
tomtomMap.addOnMapLongClickListener(onMapLongClickListener);
tomtomMap.addOnMapViewPortChangedListener(onMapViewPortChangedListener);
tomtomMap.addOnMapClickListener(showMessageWhenOnMapClick)
tomtomMap.addOnMapLongClickListener(showMessageWhenOnMapLongClick)
tomtomMap.addOnMapViewPortChangedListener(showMessageWhenOnMapViewPortChanges)

 

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 gestures settings object to tomtomMap: By default all gestures are enabled.

Disable zooming gesture

_

tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .zoomEnabled(false)
                .build()
);
tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .zoomEnabled(false)
                .build())

 

Disable the rotating gesture

_

tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .rotationEnabled(false)
                .build()
);
tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .rotationEnabled(false)
                .build()
)

 

Disable the tilting gesture

_

tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .tiltEnabled(false)
                .build()
);
tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .tiltEnabled(false)
                .build()
)

 

Disable the panning gesture

_

tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .panningEnabled(false)
                .build()
);
tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .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.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .rotationEnabled(false)
                .panningEnabled(false)
                .build()
);
tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .rotationEnabled(false)
                .panningEnabled(false)
                .build()
)

 

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

_

tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .rotationEnabled(true)
                .panningEnabled(true)
                .zoomEnabled(true)
                .tiltEnabled(true)
                .build()
);
tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettingsBuilder.create()
                .rotationEnabled(true)
                .panningEnabled(true)
                .zoomEnabled(true)
                .tiltEnabled(true)
                .build()
)

 

or even in a simpler way:

_

tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettings.createDefault()
);
tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettings.createDefault()
)