Catch double tap events on new Google Maps Android

2019-09-03 10:16发布

问题:

I have an app with a ViewSwitcher that has a MapView (v1) and another View and using a GestureDetector I can detect double taps and switch between the 2 views.

Now I'm trying to switch the app to the new Google Maps Android API V2 and I have the problem that the GestureDetector set on the MapView no longer reacts to double taps, instead the map is zooming in. Does anyone know how to change that behaviour?

I'm working with the raw MapView class, not the Map fragment.

回答1:

Okay, I found a way now. I have to create a sub class of MapView (which is actually a ViewGroup) and implement interceptTouchEvent() there to detect and catch double taps.

How this is implemented in detail is explained here: Double Tap -> Zoom on Android MapView?



回答2:

As far as I know (and according to: http://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.html), you can set to the GoogleMap object (and also to the MapView) click and long click listener. So I think you can't set a double click listener.

But you can try this:

GoogleMap map=mapView.getMap();
map.getUiSettings().setZoomGesturesEnabled(false);

And maybe it will react to your GestureDetector.