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 code snippets below 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 =
        new TomtomMapCallback.OnMapClickListener() {
            @Override
            public void onMapClick(@NonNull LatLng latLng) {
                displayMessage(
                        R.string.menu_events_on_map_click,
                        latLng.getLatitude(),
                        latLng.getLongitude()
                );
            }
        };
private TomtomMapCallback.OnMapLongClickListener onMapLongClickListener =
        new TomtomMapCallback.OnMapLongClickListener() {
            @Override
            public void onMapLongClick(@NonNull LatLng latLng) {
                displayMessage(
                        R.string.menu_events_on_map_long_click,
                        latLng.getLatitude(),
                        latLng.getLongitude()
                );
            }
        };
private TomtomMapCallback.OnMapViewPortChanged onMapViewPortChangedListener =
        new TomtomMapCallback.OnMapViewPortChanged() {
            @Override
            public void onMapViewPortChanged(float focalLatitude,
                                             float focalLongitude,
                                             double zoomLevel,
                                             float perspectiveRatio,
                                             float yawDegrees) {
                displayMessage(
                        R.string.menu_events_on_map_panning,
                        focalLatitude,
                        focalLongitude
                );
            }
        };

 

Then you just have to set them to your TomtomMap instance:

tomtomMap.addOnMapClickListener(onMapClickListener);
tomtomMap.addOnMapLongClickListener(onMapLongClickListener);
tomtomMap.addOnMapViewPortChangedListener(onMapViewPortChangedListener);

 

In this example you will see a Toast with 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 gestures settings object to tomtomMap:
By default all gestures are enabled.

Disable zooming gesture

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

 

Disable the rotating gesture

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

 

Disable the tilting gesture

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

 

Disable the panning gesture

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

 

You can turn off more than one gesture by setting up the mask on properties like below:

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

 

If you want to enable gestures, pass the GesturesDetectionSettings object to the tomtomMap object like below:

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

 

or even in the simpler way:

tomtomMap.updateGesturesDetectionSettings(
        GesturesDetectionSettings.createDefault()
);