Skip to content
MapLibre Native Android

MapLibre Native Android

MapLibre Native Android renders vector maps in native Android apps. It loads the Maptoolkit community style URL directly, with no API key.

Installation

Add the MapLibre Native dependency in your module build.gradle:

dependencies {
    implementation 'org.maplibre.gl:android-sdk:13.0.0'
}

Use the latest version from the MapLibre releases. The artifact is available on Maven Central.

Set the style URL

Initialize MapLibre before you inflate the map, then set the style with Style.Builder().fromUri().

import org.maplibre.android.MapLibre
import org.maplibre.android.camera.CameraPosition
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.maps.MapView
import org.maplibre.android.maps.Style

class MainActivity : AppCompatActivity() {
    private lateinit var mapView: MapView

    override fun onCreate(savedInstanceState: Bundle?) {
        // Must be called before setContentView
        MapLibre.getInstance(this)
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        mapView = findViewById(R.id.mapView)
        mapView.onCreate(savedInstanceState)
        mapView.getMapAsync { map ->
            map.setStyle(
                Style.Builder().fromUri("https://styles.maptoolkit.org/summer.json")
            )
            map.cameraPosition = CameraPosition.Builder()
                .target(LatLng(48.21, 16.37)) // Vienna
                .zoom(12.0)
                .build()
        }
    }

    // Forward the remaining lifecycle calls (onStart, onResume, onPause,
    // onStop, onSaveInstanceState, onLowMemory, onDestroy) to mapView.
}

Add the map view to your layout:

<org.maplibre.android.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Examples

See the Examples gallery for GeoJSON layers and runtime style switching.

Attribution

Every map must show the Maptoolkit logo (minimum 24dp) and the © Maptoolkit © OSM copyright line, both as clickable links. Keep them visible and unobstructed. See Quick Start - Add attribution.