Issue
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 zoom in / out - with a fixed center. If the user would be allowed to drag the map around, it messes with the viewpager scrolling abilities. Tried to disable clickable + focusable but - of course - no zooming anymore..
Looked at other questions here at stackoverflow but none provided a working solution so far..
Thanks!
Solution
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;
}
}
});
Answered By - Vishwa Patel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.