map view double tap event doesn't work
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(s开发者_Go百科itesOverlay);
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;
}
}
I believe you actually have to create a GestureDetector
to use it: I might be wrong, but I don't see you actually doing that anywhere in your code. Take a look at this for an example.
You could create a GestureDetector to handle this action, but also you can implement some ticks like this (that works):
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;
}
...
}
hope it helps..
精彩评论