• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

MapView Gestures detector

This example shows Gestures detectors on MapView

  • Gestures detectors on MapView

  • Enable/Disable Gesture detector on Mapview

MapView Gestures detector

For all code examples, refer to Android Maps SDK Code Examples

activity_gesture_detector.xml view source

1<?xml version="1.0" encoding="utf-8"?>
2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:app="http://schemas.android.com/apk/res-auto"
4 xmlns:tools="http://schemas.android.com/tools"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent">
7
8 <ai.nextbillion.maps.core.MapView
9 android:id="@id/mapView"
10 android:layout_width="match_parent"
11 android:layout_height="match_parent"
12 app:nbmap_localIdeographEnabled="false"
13 app:nbmap_cameraTargetLat="51.50325"
14 app:nbmap_cameraTargetLng="-0.11968"
15 app:nbmap_cameraZoom="15" />
16
17 <androidx.recyclerview.widget.RecyclerView
18 android:id="@+id/alerts_recycler"

GestureDetectorActivity view source

1package ai.nextbillion;
2
3import android.graphics.Typeface;
4import android.os.Bundle;
5import android.os.Handler;
6import android.view.LayoutInflater;
7import android.view.Menu;
8import android.view.MenuItem;
9import android.view.View;
10import android.view.ViewGroup;
11import android.widget.RelativeLayout;
12import android.widget.TextView;
13
14import java.lang.annotation.Retention;
15import java.util.ArrayList;
16import java.util.List;
17
18import ai.nextbillion.gestures.AndroidGesturesManager;

The code provided is an Android activity called GestureDetectorActivity. It showcases various APIs related to gesture implementation. Here is a summary of the code:

Initialization of MapView:

  • The MapView is instantiated and initialized in the onCreate() method using findViewById().

  • The map is asynchronously loaded using getMapAsync(), and the initialization of the map is done in the callback.

  • The map style is set to "NBMAP_STREETS" using the setStyle() method.

  • The camera position is set to a specific location with a target LatLng, zoom level and tilt using the CameraPosition.Builder and moveCamera() methods.

Gesture Detectors on MapView:

  • setOnTouchListener(View.OnTouchListener listener): Sets an OnTouchListener to receive touch events for the map view.

  • setOnMapClickListener(MapView.OnMapClickListener listener): Sets a listener to be invoked when the map is clicked.

  • setOnMapLongClickListener(MapView.OnMapLongClickListener listener): Sets a listener to be invoked when the map is long-clicked.

  • setOnMapDoubleClickListener(MapView.OnMapDoubleClickListener listener): Sets a listener to be invoked when the map is double-clicked.

  • setOnMapScaleListener(MapView.OnMapScaleListener listener): Sets a listener to be invoked when the map scale changes.

  • setOnMapScrollListener(MapView.OnMapScrollListener listener): Sets a listener to be invoked when the map is scrolled.

  • setOnMapFlingListener(MapView.OnMapFlingListener listener): Sets a listener to be invoked when the map is flung.

  • setOnMapRotateListener(MapView.OnMapRotateListener listener): Sets a listener to be invoked when the map is rotated.

  • setOnMapTranslateListener(MapView.OnMapTranslateListener listener): Sets a listener to be invoked when the map is translated.

  • setOnMapPinchListener(MapView.OnMapPinchListener listener): Sets a listener to be invoked when the map is pinched.

  • setOnMapSingleFingerTapListener(MapView.OnMapSingleFingerTapListener listener): Sets a listener to be invoked when the map is single-finger tapped.

  • setOnMapTwoFingerTapListener(MapView.OnMapTwoFingerTapListener listener): Sets a listener to be invoked when the map is two-finger tapped.

Enable/Disable Gesture Detectors on MapView:

  • setRotateGesturesEnabled(boolean enabled): Enables or disables rotate gestures on the map.

  • isRotateGesturesEnabled(): Returns whether rotate gestures are enabled or not.

  • setTiltGesturesEnabled(boolean enabled): Enables or disables tilt gestures on the map.

  • isTiltGesturesEnabled(): Returns whether tilt gestures are enabled or not.

  • setZoomGesturesEnabled(boolean enabled): Enables or disables zoom gestures on the map.

  • isZoomGesturesEnabled(): Returns whether zoom gestures are enabled or not.

  • setScrollGesturesEnabled(boolean enabled): Enables or disables scroll gestures on the map.

  • isScrollGesturesEnabled(): Returns whether scroll gestures are enabled or not.

  • setDoubleTapGesturesEnabled(boolean enabled): Enables or disables double-tap gestures on the map.

  • isDoubleTapGesturesEnabled(): Returns whether double tap gestures are enabled or not.

  • setQuickZoomGesturesEnabled(boolean enabled): Enables or disables quick zoom gestures on the map.

  • isQuickZoomGesturesEnabled(): Returns whether quick zoom gestures are enabled or not.

  • setHorizontalScrollGesturesEnabled(boolean enabled): Enables or disables horizontal scroll gestures on the map.

  • isHorizontalScrollGesturesEnabled(): Returns whether horizontal scroll gestures are enabled or not.

  • setFlingVelocityAnimationEnabled(boolean enabled): Enables or disables fling velocity animation.

  • isFlingVelocityAnimationEnabled(): Returns whether fling velocity animation is enabled or not.

  • setScaleVelocityAnimationEnabled(boolean enabled): Enables or disables scale velocity animation.

  • isScaleVelocityAnimationEnabled(): Returns whether scale velocity animation is enabled or not.

  • setRotateVelocityAnimationEnabled(boolean enabled): Enables or disables rotate velocity animation.

  • isRotateVelocityAnimationEnabled(): Returns, whether rotate velocity animation, is enabled or not.

  • setFocalPoint(PointF point): Sets the focal point on the map for gestures.

  • getFocalPoint(): Returns the current focal point on the map for gestures.

Overall, the code demonstrates how to implement and manage gesture detectors on a MapView in an Android application.

Have Questions ?