androidandroid-studiomapboxmapbox-androidandroid-studio-3.1.3

Android: how to use mapbox setZoomControlsEnabled?


I just start today using mapbox for android. I want to display zoom control on mapbox mapview. I did a little research, the method should be setZoomControlsEnabled. but I dont know how to use this method on mapbox android sdk v6.3.0. the documentation pretty clear: https://www.mapbox.com/android-docs/api/map-sdk/6.3.0/index.html?com/mapbox/mapboxsdk/maps/UiSettings.html . But how I can use it?

another info about setZoomControlsEnabled, it should be a method of mapView class and can be called like this:

mapView.setZoomControlsEnabled

but I tried and it doesn't work. a github link as reference: https://github.com/mapbox/mapbox-gl-native/issues/2537


Solution

  • You can use MapboxMap object get the reference to the UiSettings:

    mapView.getMapAsync(mapboxMap -> {
      mapboxMap.getUiSettings().setZoomControlsEnabled(true);
    }
    

    or use the XML attributes:

    <com.mapbox.mapboxsdk.maps.MapView
        android:id="@id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:mapbox_uiZoomControls="true" />
    

    Also, check out the first steps and docs.