0

I am using following code to show the MAP (Google API) I want it to zoom when user DOUBLE clicks any where on the map. How can I achieve it?

public class TourMapActivity extends MapActivity {


@Override
protected void onCreate(Bundle arg0) {

    super.onCreate(arg0);

    setContentView(R.layout.tour_map);
    mMapView = (MapView)findViewById(R.id.MapView);
    mMapView.setBuiltInZoomControls(true);
    mMapView.getZoomButtonsController().setVisible(true);




}


@Override
protected boolean isRouteDisplayed() {

    return true;
}

class CustomOverlay extends ItemizedOverlay<CustomItem> {

    protected ArrayList<CustomItem> mOverlays = new ArrayList<CustomItem>();
    public OnTapListenerIndex mOnTapListenerIndex = null;
    private Context mContext;

    public CustomOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));
    }


    public CustomOverlay(Drawable defaultMarker, Context context)
    {
        super(boundCenterBottom(defaultMarker));
        mContext = context;
    }

    @Override
    protected CustomItem createItem(int i) {
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        return mOverlays.size();
    }

    public void addOverlay(CustomItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    public void addOverlay(CustomItem overlay, Drawable marker) {
        overlay.setMarker(boundCenterBottom(marker));
        addOverlay(overlay);
    }

    @Override
    public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, false);
    }




}

public interface OnTapListenerIndex {

    public void onTapEvent(int index, OverlayItem overlayItem);
}

}

I want it to zoom when user double clicks any where on the map. How can I achieve it?

iShare
  • 125
  • 3
  • 16

1 Answers1

0

Have a look at this: https://stackoverflow.com/a/12646465/1885518 or http://nocivus.posterous.com/double-clicktap-detection-on-a

In short override onInterceptTouchEvent()

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (ev.getAction() == MotionEvent.ACTION_DOWN) {

        long thisTime = System.currentTimeMillis();
        if (thisTime - lastTouchTime < 250) {

            // Double tap
            this.getController().zoomInFixing((int) ev.getX(), (int) ev.getY());
            lastTouchTime = -1;

        } else {
            lastTouchTime = thisTime;
        }
   }
}
Community
  • 1
  • 1
Murmel
  • 5,402
  • 47
  • 53