Double Tap to Zoom Feature for Map Fragment
Asked Answered
P

2

9

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.

Poniard answered 14/12, 2018 at 7:48 Comment(24)
@King of Masses I clearly mention that its for Map Fragment not MapView. Please read the question properly before adding any duplicate tags.Poniard
Ok. reopened the questionUntouchability
Is there any chance you can provide more code (and XML)? I have an application with a MapFragment and the zoom just works "out of the box".Mantelet
@Mantelet I updated the question with some codes and xml..please free to ask anything.Poniard
@Poniard are you able to get click listener and map object in your code?Polymorphonuclear
@KaranMer I didn't get which clicklistener you are asking for. googleMap object I am able to get ..that getmap() method is returning the map object which I have written.Poniard
@Poniard can you try to set OnDoubleTapListener to your fragment? it has ondouble tap method.Polymorphonuclear
@KaranMer OnDoubleTapListener is not there unfortunately..Its for MapView but i am using MapFragmentPoniard
it is interface, you can implement it to your fragment.Polymorphonuclear
@Poniard my thought was maybe there's another view that is intercepting the touch event, I've tried to add some of your code but it is still working for meMantelet
@Ranjit: if you can get hold of your map object you can zoom using map.animateCamera(CameraUpdateFactory.zoomIn());, how you capture the event its upto you.Polymorphonuclear
@Mantelet Can you extend only Activity instead of AppCompact and check pleasePoniard
@KaranMer let me try that interfacePoniard
@Poniard my changes include changing to Activity (and using fragmentManager) - off topic: why don't you use the AppCompatActivity?Mantelet
@Mantelet Its an obstacle for me to change for the current project in which i am working due to the lead unfortunately. Anyways I need to check why its not coming. will update you soonPoniard
@Poniard : did you checked it?Polymorphonuclear
@KaranMer i still not able to understand how to start. if I implement the interface to my class then all override methods will come like doubleTp and onTouch.. etc..then what ?Poniard
are you able to get your map object in fragment? if yes, then in your desired event you can use map.animateCamera(CameraUpdateFactory.zoomIn());Polymorphonuclear
@KaranMer I did it but how to link the interface..like getMap().doubleClick or somthing like thisPoniard
@Ranjit: are you able to get your map object in your fragment? there will be onDoubleTapEvent() write map.animateCamera(CameraUpdateFactory.zoomIn()); in it.Polymorphonuclear
@KaranMer Yes I can see onDoubleTap is there and I wrote also these zoonin stuffs..I implemented the DoubleTap interface and add your code in onDoubleTap event..is that all ? I need to all something to link that interface event to my map right same like how we are doing for onClick i.e getMap().setOnClickListener(this) etcPoniard
map.animate camera will do it. debug and check whether your event is being receivedPolymorphonuclear
if you are not able to get event, check solution here to set gesture listener to view. #45055408Polymorphonuclear
did you try linkBerlyn
P
2

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.

Poniard answered 21/12, 2018 at 7:17 Comment(0)
W
2

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);
}
}
Wergild answered 14/12, 2018 at 9:14 Comment(2)
Vaibhav, I don't think any settings will work. I hope there should be something like method or listener which will handle the double click/tap in MapFragment. setZoomGesturesEnabled might be the flag to kick start.Poniard
Lets see.. need to dig deeper. Code which i have working properly. I will check again Sir , Thank youWergild
P
2

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.

Poniard answered 21/12, 2018 at 7:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.