Skip to content

Instantly share code, notes, and snippets.

@jgilfelt
Created February 8, 2012 14:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgilfelt/1769883 to your computer and use it in GitHub Desktop.
Save jgilfelt/1769883 to your computer and use it in GitHub Desktop.
Android - MapView implementing double tap to zoom
public class DoubleTapZoomMapView extends MapView {
private static final long TIME_INITIAL = -1;
private static final long TIME_DOUBLE_TAP = 250;
private long lastTouchTime = TIME_INITIAL;
public DoubleTapZoomMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DoubleTapZoomMapView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public DoubleTapZoomMapView(Context context, String apiKey) {
super(context, apiKey);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
long thisTime = System.currentTimeMillis();
if (thisTime - lastTouchTime <= TIME_DOUBLE_TAP) {
this.getController().zoomInFixing((int) ev.getX(), (int) ev.getY());
lastTouchTime = TIME_INITIAL;
} else {
lastTouchTime = thisTime;
}
}
return super.onInterceptTouchEvent(ev);
}
}
@nyaray
Copy link

nyaray commented Jul 5, 2013

Why is this not presented by google as "Oh, hey, here is EXACTLY what you wanted" when you search for "double tap to zoom android mapview"?

Thanks for sharing <3

@ZainKalim-dev
Copy link

What we have to use instead of getcontroller() in Google Maps V2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment