I\'m trying to implement a double-tap zoom like function in my MapView. The event always fires the first time, but never subsequent times. Below is my code. I have a feeling
I was having the same problem - I couldn't drag and scroll the map because it was receiving only ACTION_DOWN
events. It can be solved by adding android:clickable="true"
to the MapView
or by calling mapView.setClickable(true)
.
How about using a GestureDetector.OnDoubleTapListener instead of OnTouchListener
?
If you are using this method "mapView.setBuiltInZoomControls(true);"
then your touch
is working at once .
Please remove that that line and check I am sure it will work..
In some case if you want BuiltInZoomControls then you can you OnTouch method of Overlay like as below..
public class MapOverlay extends Overlay {
public MapOverlay(Context ctx) {super(ctx);}
@Override
protected void draw(Canvas c, MapView osmv, boolean shadow) { }
@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView) {
//Write yout touch code here..
return false;
}
}
Implement the Touch event on the map view instead. That will work!!
// The onTouch event of the Map itself does not fire!
// We must implement it on the mapView!!!
mapView.setOnTouchListener(new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
// Your code and remember to return true!
return (true);
}
});
Subclass MapView and override dispatchTouchEvent like below and use the subclass instead.
public class MyMap extends MapView{
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mOnMovedListener!= null) {
mOnMovedListener.onMove(ev);
}
return super.dispatchTouchEvent(ev);
}
private OnMovedListener mOnMovedListener;
public void setOnMovedListener(OnMovedListener mOnMovedListener) {
this.mOnMovedListener= mOnMovedListener;
}
}
register for listener like any other!
you should at least put
lasttime=event.getEventTime();
under the
if (event.getAction() == MotionEvent.ACTION_DOWN) brakes
while onTouch
detect ACTION_UP
event of your click. So any time you make a click it is called 2 times