双击Google Map API中的缩放 - Android

时间:2012-12-07 14:51:04

标签: android google-maps

我使用以下代码显示MAP(Google API) 当用户DOUBLE点击地图上的任何位置时,我希望它可以缩放。我怎样才能实现它?

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);
}

}

我希望在用户双击地图上的任何位置时进行缩放。我怎样才能实现它?

1 个答案:

答案 0 :(得分:0)

请看一下:https://stackoverflow.com/a/12646465/1885518http://nocivus.posterous.com/double-clicktap-detection-on-a

简短覆盖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;
        }
   }
}