0

我正在使用以下代码显示 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);
}

}

当用户双击地图上的任何位置时,我希望它可以缩放。我怎样才能实现它?

4

1 回答 1

0

看看这个:https ://stackoverflow.com/a/12646465/1885518或http://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;
        }
   }
}
于 2012-12-07T15:05:37.227 回答