Change the map style using MapBox on Android

1

I have a map loaded with Mapbox but I can not find a way to change the default style. Bring a street map, here it is in the xml code of the view:

<com.mapbox.mapboxsdk.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    mapbox:mapbox_cameraTargetLat="40.73581"
    mapbox:mapbox_cameraTargetLng="-73.99155"
    mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10"
    mapbox:mapbox_cameraZoom="11" />

I would think it's styleUrl but I can not find it in the documentation to change it for satellite type, for example

    
asked by Igmer Rodriguez 15.11.2018 в 22:02
source

1 answer

1

You can define the style in the mapbox: mapbox_styleUrl property, but the value must be a url :

mapbox:mapbox_styleUrl="https://..."

in the example that shows your question you are making the definition as done on the web ( "mapbox://styles/mapbox/streets-v10" ), which is incorrect on Android.

on the style page you can get the url of the style you want to define.

You must enter the page link and register, there you can use a template or upload a style:

There, select the url of the desired style, in this case "Satellite":

You can add this value to your file strings.xml

<string name="style_satelite">https://api.mapbox.com/styles/v1/jorgesys/cjoj4c2g1310u2rntda2bk8f7.html?fresh=true&title=true&access_token=pk.abJ1Ijoiam9yZ2VzeXMiLCJhIjoiY2pvajQ4bW9kMDB</string>

and call it in your sight:

<com.mapbox.mapboxsdk.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    mapbox:mapbox_cameraTargetLat="40.73581"
    mapbox:mapbox_cameraTargetLng="-73.99155"
    mapbox:mapbox_styleUrl="@strings/style_satelite"
    mapbox:mapbox_cameraZoom="11" />
    
answered by 15.11.2018 / 22:31
source