When user zooms map via multitouch it is always tapped on an item in my ItemizedOverlay.
How to make my MapView to not call onTap of overlay if user actually multitouches for rezooming?
I ran into this problem too.
rohit mandiwal's idea is good, but if user, for example, zooms in and then zooms out to the same level, unwanted tap event may still occur.
Solution to this is to detect zoom level change in onTouchEvent()
rather than in onTap()
. I tried this, and it seems to work.
Here's my code:
private class LocationOverlay extends ItemizedOverlay<OverlayItem> {
private int lastZoomLevel;
private boolean onTapAllowed;
public LocationOverlay(...) {
//...
lastZoomLevel=mapView.getZoomLevel();
}
@Override
public boolean onTouchEvent(MotionEvent motionEvent, MapView mapView) {
if (mapView.getZoomLevel()!=lastZoomLevel) {
lastZoomLevel=mapView.getZoomLevel();
onTapAllowed=false;
}
return super.onTouchEvent(motionEvent, mapView);
}
@Override
public boolean onTap(GeoPoint geoPoint, MapView mapView) {
if (!onTapAllowed) {
Log.d("onTap","onTap cancelled, zoom level changed...");
lastZoomLevel=mapView.getZoomLevel();
onTapAllowed=true;
return true;
}
//...
}