Disable moving around in mapview

2019-02-11 16:18发布

Is it possible to disable moving inside the google map?

7条回答
Emotional °昔
2楼-- · 2019-02-11 16:33

We can stop user interactions with MapView or SupportMapFragment using GoogleMapOptions

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val mapOptions = GoogleMapOptions()
        mapOptions.rotateGesturesEnabled(false)
        mapOptions.zoomGesturesEnabled(false)
        mapOptions.tiltGesturesEnabled(false)
        mapOptions.scrollGesturesEnabled(false)

        // Map View
        val mapView = MapView(context, mapOptions)
        mapView.onCreate(savedInstanceState)

        // Or
        val mapView = MapView(context
        mapView.getMapAsync { googleMap ->
           googleMap.uiSettings.setAllGesturesEnabled(false) 
        }

       // Or Map Fragment
       val mapFragment = SupportMapFragment.newInstance(mapOptions)
}
查看更多
Animai°情兽
3楼-- · 2019-02-11 16:37
mMap.getUiSettings().setScrollGesturesEnabled(false);

this can disable moving in map

查看更多
可以哭但决不认输i
4楼-- · 2019-02-11 16:40

If you embed the map view in your app, I think you can use static maps to view the same.

查看更多
地球回转人心会变
5楼-- · 2019-02-11 16:43

Even though there is an accepted answer, just providing my answer as it didnt help me. mapView.setClickable(false) does not work all the time, like cases where you have a mapView inside a scrollView. So I created a view object right above the mapView of the same size.

Handled the onTouchListener for my overlay view and passed all the touch events to the parent of mapView (ScrollView in my case), hence by-passing all the touch events from mapView to scrollview.

One more way to achieve is by doing

mMap.getUiSettings().setAllGesturesEnabled(false);
查看更多
做自己的国王
6楼-- · 2019-02-11 16:45

Perhaps this could be a solution:

mapView.setEnabled(false)

查看更多
仙女界的扛把子
7楼-- · 2019-02-11 16:53

I created customMapView that extends MapView and override the onInterceptTouchEvent method.

public class customMapView extends MapView {
    public customMapView(Context context) {
        super(context);
    }

    public customMapView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    public customMapView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
    }

    public customMapView(Context context, GoogleMapOptions googleMapOptions) {
        super(context, googleMapOptions);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

//      return super.onInterceptTouchEvent(ev);
        return true;
    }

}
查看更多
登录 后发表回答