Search code examples
javaandroidandroid-maps-v2

Double Tap to Zoom Feature for Map Fragment


I did this for MapView before and it was pretty simple czuse there were predefined methods like onInterceptTouchEvent or GestureListeners etc.

Did anyone try this double tap or double click zoom feature in Map Fragment as well. I googles but still not able to found any solution.

i just started it by adding the UiSettings only getMap().getUiSettings().setZoomGesturesEnabled(true);

Will it be implemented by the help of setOnMapClickListener() or something is there to handle the gesture for double tap event for Map Fragment ?

NOTE: This question purely on MapFragment and not related to MapView which have already answers Double tap: zoom on Android MapView?

EDIT MapFragment which I used in the layout:

<ViewFlipper
        android:id="@+id/viewFlipper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/noItemsText"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:addStatesFromChildren="true"
        android:background="@android:color/transparent"
        android:gravity="center">

        <ListView
            android:id="@+id/storesListView"
            style="@style/Fill"
            android:background="@android:color/transparent"
            android:cacheColorHint="#00000000" />

        <fragment
            android:id="@+id/mapview"
            android:name="com.google.android.gms.maps.MapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </ViewFlipper>

The class is a controller which is working for the Activity which extends Activity not AppCompactActivity.

Also I added marker clustering in the map.

Class side:

public class StoreFinderController extends BeeonicsControllerBase implements OnMapReadyCallback,
    ClusterManager.OnClusterItemInfoWindowClickListener<AllClusterItems>,ClusterManager.OnClusterClickListener<AllClusterItems> {

onMapReady:

@Override
public void onMapReady(GoogleMap googleMap) {

    /*better to work with our map :)*/
    this.googleMap = googleMap;

    mClusterManager = new CustomClusterManager<AllClusterItems>(getActivity(), getMap());
    getMap().setOnCameraIdleListener(mClusterManager);
    getMap().setOnInfoWindowClickListener(mClusterManager);
    getMap().setOnMarkerClickListener(mClusterManager);
    mClusterManager.setOnClusterItemInfoWindowClickListener(this);
    mClusterManager.setOnClusterClickListener(this);

    /*map additional settings*/
    setUpMap();

    //setUpGoogleMap();
    //readItems();
}

And inside setUpMap I am simply transferring some data in between objects.


Solution

  • I tried all possible solutions from here and here in which they have given some other ways to handle the double tap by the help of the touch event. But unfortunately nothing worked for me.

    So I ended with the predefined onMapClickListener() which calls on a single click of the map. I pasted my solution below:

     getMap().setOnMapClickListener(new GoogleMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng latLng) {
                getMap().animateCamera(CameraUpdateFactory.zoomIn());
            }
        });
    

    Anyways thanks Karan Mer for the help.