Double-Tap to Zoom in Android Maps

Double-Tap to zoom is a typical feature for mapped interfaces on Android. Sometimes it’s just annoying trying to reverse-pinch to zoom with one hand while holding a device.

This is something that’s not technically difficult to do, but it’s not documented very well.

Here’s how to do it:

  1. Write a class that inherits from MapView, and add a GestureDetector to the child class. Then, override the onTouchEvent(MotionEvent event) method and pass the MotionEvent along to your GestureDetector:

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.MotionEvent;
import android.view.GestureDetector.OnGestureListener;

public class MyMapView extends MapView
	private GestureDetector gestureDetector;

	public MyMapView(Context context, AttributeSet attrs)
		super(context, attrs);

		gestureDetector = new GestureDetector((OnGestureListener) context);
		gestureDetector.setOnDoubleTapListener((OnDoubleTapListener) context);
	public boolean onTouchEvent(MotionEvent ev)
		return this.gestureDetector.onTouchEvent(ev);
  1. Refer to this child class in your layout XML file, instead of the regular MapView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
	android:layout_width="fill_parent" android:layout_height="fill_parent">
	<RelativeLayout xmlns:android="" 

	    android:apiKey="YOUR_API_KEY" />

  1. Implement the OnGestureListener and OnDoubleTapListener interfaces in your MapActivity class, and write some code to zoom-in the map in the onDoubleTap(MotionEvent e) method:
public class Map extends MapActivity 
    implements OnGestureListener, OnDoubleTapListener {
 // More map stuff here, and additional forced overrides from the interfaces
 public boolean onDoubleTap(MotionEvent e) {
      // Assuming your MapView is called mapView
     return true;

And that’s it! Your map will now zoom-in when the user double-taps.

About this entry