Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 846
Ranjit Avatar asked Dec 14 '18 07:12

Ranjit


1 Answers

Have You tried to set your listener onMapReady() call back? and then set

mMap.getUiSettings().setZoomGesturesEnabled(true);

@Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
 mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng latLng) {
                try {


                //   mMap.clear();
                    mMap.getUiSettings().setZoomGesturesEnabled(true);
}
}
like image 63
flashberry Avatar answered Oct 23 '22 06:10

flashberry