Skip to content Skip to sidebar Skip to footer

Mapview - Disable Dragging Around, But Allow Zooming

I have a ViewPager with 3 fragments inside, on the outer right I want to display a MapView - working fine so far. But I'd like to disable dragging it around, but still let the user

Solution 1:

Ignore everything I've said so far (which is why I've edited my answer), instead use the following code in your MapActivity class(it works perfectly, just tried it!):

final GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
final MapController mapController = mapView.getController();

mapController.animateTo(point);
mapController.setZoom(6);

mapView.setOnTouchListener(new View.OnTouchListener() {

@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
  if(arg1.getAction() ==  MotionEvent.ACTION_UP)
  {
    mapController.setCenter(point);
    return true;
  }
  if(arg1.getPointerCount() > 1)
  {
   mapController.setCenter(point);
   return false;
  }
  else
  {
   return true;
  }
 } 
 });

Post a Comment for "Mapview - Disable Dragging Around, But Allow Zooming"