Search code examples
androidgoogle-mapsonfling

Google Maps fling event


Is there any way to disable fling gesture on google map (SupportMapFragment)? Or I need at least an event to detect when map scrolling ends after fling and to compute map camera location.

Thanks.


Solution

  • You can set an OnCameraIdleListener. From the documentation:

    onCameraIdle()

    Called when camera movement has ended, there are no pending animations and the user has stopped interacting with the map

    Thake into account that OnCameraIdleListener is one of the events that replace the deprecated OnCameraChangeListener (documentation).

    You can get the new camera position like this:

    @Override
    public void onCameraIdle() {
        CameraPosition cameraPosition = mMap.getCameraPosition();
    }
    

    You can know whether the user initiated the camera update event if you use the OnCameraMoveStartedListener. The method onCameraMoveStarted(int reason) provides a reason that equals REASON_GESTURE if the update has been initiated by the user. From the documentation

    onCameraMoveStarted(int reason)

    Called when the camera starts moving after it has been idle or when the reason for camera motion has changed.