Unwanted Tap on an Item in ItemizedOverlay during zooming via multi touch
When user zooms map via multitouch it is always t开发者_运维技巧apped on an item in my ItemizedOverlay.
How to make my MapView to not call onTap of overlay if user actually multitouches for rezooming?
You can get the zoom level of current map view in your onTap method and if you found it differ from the previous one you can call return
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;
}
//...
}
精彩评论