Android Google Maps: disable dragging in MapFragment

♀尐吖头ヾ 提交于 2019-11-29 04:24:16

问题


Can I disable drag functionality when the user tries to drag the map with his fingers without disturbing the Zoom in and Zoom out?

Any one please suggest an idea of doing this! Thanks for your Precious help!!


回答1:


I think here's what you're looking for:

Inside Google Maps Android v2

Scroll (pan) gestures

A user can scroll (pan) around the map by dragging the map with their finger. You can disable scrolling by calling UiSettings.setScrollGesturesEnabled(boolean).




回答2:


You can disable dragging in MapFragment using:

googleMap.getUiSettings().setScrollGesturesEnabled(false);



回答3:


for disable dragging in MapFragment this code :

googleMap.getUiSettings().setScrollGesturesEnabled(false);

works as @tomrozb said. but it dosn't disable map zoom by touch on map. for that use this code beside above code:

googleMap.getUiSettings().setZoomGesturesEnabled(false);



回答4:


you can use isScrollGesturesEnabled for map

java:

googleMap.getUiSettings().setZoomGesturesEnabled(false);

kotlin

googleMap?.uiSettings?.isScrollGesturesEnabled = false



回答5:


You don't have to set this in code. You can configure the gestures from XML:

<fragment
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:id="@+id/mapFragment"
    map:uiScrollGestures="false" />

As well as uiScrollGestures, you can set uiZoomGestures, uiTiltGestures, and uiRotateGestures.

See XML Attributes documentation.



来源:https://stackoverflow.com/questions/16979550/android-google-maps-disable-dragging-in-mapfragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!