Sitemap

Mapbox Android Tutorial

1 min readJan 11, 2019

--

What is Mapbox?

Step by step how to use it?

Step 1. Create a new project in Android Studio

Step 2. Sign up by going to this link https://www.mapbox.com and get your access token namely default public token in account section.

Get bikram’s stories in your inbox

Join Medium for free to get updates from this writer.

Step 3. Add dependency in build.gradle (app)

dependencies{
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.8.0'
}

And in your build.gradle (root)

allprojects {
repositories {
...
mavenCentral()
}
}

Step 3. In your Activity/Fragment get the instance of Mapbox and initialize callback.

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Mapbox.getInstance(this, "your_access_token"); MapView mapView = findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); mapView.getMapAsync(mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
//do your stuff
}
});
}

Step 4. In your activity/fragment xml file add 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_renderTextureMode="true"
mapbox:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
mapbox:mapbox_cameraZoom="11"
/>

--

--