地图视图双击事件不起作用

时间:2011-08-26 05:55:42

标签: android android-maps

In my application i want to implement double tap event on map view.For this I'm using following code but doesn't seem to work.Please help me...
Thanks in advance!!
public class NooYawk extends MapActivity implements OnGestureListener, OnDoubleTapListener  {
    private MapView map=null;
    private MyLocationOverlay me=null;
    GeoPoint geoPoint;
    MapController controller;
    OverlayItem overlayItem;
    PushPinMapView pushPinMapView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        map=(MapView)findViewById(R.id.map);

        //  map.getController().setCenter(getPoint(40.76793169992044,-73.98180484771729));
        controller=map.getController();
        map.setStreetView(true);
        map.setBuiltInZoomControls(true);

        Drawable marker=getResources().getDrawable(R.drawable.blue);
        marker.setBounds(0, 0, marker.getIntrinsicWidth(),
                marker.getIntrinsicHeight());

        geoPoint=new GeoPoint((int)(19.182 *1E6 ),(int)(72.961 * 1E6));
        controller.animateTo(geoPoint);
        overlayItem=new OverlayItem(geoPoint, "Current loc","");
        List<Overlay> listOverlays= map.getOverlays();
        SitesOverlay sitesOverlay=new SitesOverlay(marker);
        sitesOverlay.addOverlay(overlayItem);
        listOverlays.add(sitesOverlay);
        controller.setZoom(6);

    }
@Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }


    private class SitesOverlay extends ItemizedOverlay<OverlayItem> {
        private List<OverlayItem> items=new ArrayList<OverlayItem>();

        public SitesOverlay(Drawable marker) {
            super(marker);


        }

        @Override
        protected OverlayItem createItem(int i) {
            return(items.get(i));
        }

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

            boundCenterBottom(marker);
        }

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

        public void addOverlay(OverlayItem overlay) {

            items.add(overlay);

            //System.out.println("success");

            populate();

        }
}



@Override
    public boolean onDown(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
            float distanceY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        controller.zoomIn();
        return false;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

}

2 个答案:

答案 0 :(得分:0)

我相信你实际上必须创建一个GestureDetector来使用它:我可能错了,但我没有看到你在代码中的任何地方都这样做。请查看this示例。

答案 1 :(得分:0)

你可以创建一个GestureDetector来处理这个动作,你可以实现这样的一些滴答(可行):

private long lastTouchTime = -1;

@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView) {
  long thisTime = System.currentTimeMillis();
  // 250 in TimeMillis is a good interval limit for a double click
  if (thisTime - lastTouchTime < 250) {
     // this is a double touch / tap
     lastTouchTime = -1;
  }else {
     // this is a single touch / tap
     lastTouchTime = thisTime;
  }
...
}
希望它有所帮助..