All skills
mapbox avatar

/mapbox-android-patterns

@f5ae7de official
by mapboxmapbox/mapbox-agent-skills80 stars
17

Official integration patterns for Mapbox Maps SDK on Android. Covers installation, adding markers, user location, custom data, styles, camera control, and featureset interactions. Based on official Mapbox documentation.

Use this Skill: https://skilld.dev/gh/mapbox/mapbox-agent-skills/mapbox-android-patterns

This session only. Nothing lands on disk.

referencescompose.md

≈904 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Jetpack Compose Integration

Compose-specific patterns for Mapbox Maps SDK v11.

Dependencies

dependencies {
    implementation("com.mapbox.maps:android:11.18.1")
    implementation("com.mapbox.extension:maps-compose:11.18.1")
}

Check releases for the latest version. Both artifacts must use the same version.

The Compose extension group is com.mapbox.extension, NOT com.mapbox.maps. These do NOT exist: com.mapbox.maps:compose, com.mapbox.maps:extension-compose, com.mapbox.maps:android-compose, com.mapbox.maps:maps-compose.

Access Token

Create app/src/main/res/values/mapbox_access_token.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <string name="mapbox_access_token" translatable="false"
        tools:ignore="UnusedResources">YOUR_MAPBOX_ACCESS_TOKEN</string>
</resources>

The SDK reads this resource automatically. This is the recommended approach.

To set the token programmatically, import from com.mapbox.common (NOT com.mapbox.maps):

import com.mapbox.common.MapboxOptions
MapboxOptions.accessToken = "pk.your_token"

Do NOT use manifest <meta-data> placeholders — the SDK does not read tokens from ${MAPBOX_ACCESS_TOKEN} in AndroidManifest.xml.

MapboxMap Composable

import com.mapbox.maps.extension.compose.MapboxMap
import com.mapbox.maps.extension.compose.animation.viewport.rememberMapViewportState
import com.mapbox.geojson.Point

@Composable
fun MapScreen() {
    MapboxMap(
        modifier = Modifier.fillMaxSize(),
        mapViewportState = rememberMapViewportState {
            setCameraOptions {
                center(Point.fromLngLat(-122.4194, 37.7749))
                zoom(12.0)
            }
        }
    )
}

rememberMapViewportState is in com.mapbox.maps.extension.compose.animation.viewport, not the root compose package.

Point Annotations

import com.mapbox.maps.extension.compose.annotation.generated.PointAnnotation
import com.mapbox.maps.extension.compose.annotation.rememberIconImage

@Composable
fun MapWithMarkers() {
    val markerIcon = rememberIconImage(R.drawable.ic_marker)

    MapboxMap(modifier = Modifier.fillMaxSize(), mapViewportState = ...) {
        PointAnnotation(point = Point.fromLngLat(lng, lat)) {
            iconImage = markerIcon
            interactionsState.onClicked { /* handle tap */ true }
        }
    }
}
  • PointAnnotation renders nothing without iconImage — always set it
  • Use rememberIconImage(R.drawable.ic_marker) for drawable resources
  • Use interactionsState.onClicked { ... } for tap handling (the onClick parameter is deprecated)
  • Annotation IDs are Long, not String

Loading GeoJSON from Assets

import com.mapbox.geojson.FeatureCollection
import com.mapbox.geojson.Point

val json = context.assets.open("data.geojson").bufferedReader().use { it.readText() }
val features = FeatureCollection.fromJson(json).features() ?: emptyList()
features.forEach { feature ->
    val point = feature.geometry() as Point
    val name = feature.getStringProperty("name")
}

MapEffect

Use MapEffect for imperative style and layer operations (prefer PointAnnotation composable for markers):

import com.mapbox.maps.extension.compose.MapEffect

MapboxMap(...) {
    MapEffect(Unit) { mapView ->
        // Style operations, custom layers, etc.
    }
}

Import is com.mapbox.maps.extension.compose.MapEffect, not LaunchedEffect from Compose runtime.

Source: SKILL.md on GitHub

1 warning16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides official integration patterns for the Mapbox Maps SDK for Android. It uses official Mapbox repositories and follows standard Android development best practices for secret management and permissions.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    2/2 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at f5ae7de. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 hours ago.

Activeupdated 2 months ago
  • mapbox
  • android
  • kotlin
  • jetpack-compose
  • maps
  • annotations
  • geolocation
  • gis

README badge

README badge for mapbox/mapbox-agent-skills/mapbox-android-patterns

Official patterns for integrating Mapbox Maps SDK v11 on Android with Kotlin, Jetpack Compose, and the View system. Covers initialization, markers, user location display, custom data, styles, camera control, and feature interactions.

Generated from the current SKILL.md.

Does this skill cover both Jetpack Compose and the View system?
Yes. The skill includes patterns for both Jetpack Compose and the traditional View system, with separate code examples for each approach.
What is the minimum Android SDK version required?
Android SDK 21 or higher is required.
Do I need to configure an access token before using Mapbox Maps?
Yes. You must create a Mapbox account, get an access token, and store it in `app/res/values/mapbox_access_token.xml` for the SDK to work.
Does this skill cover GeoJSON, custom layers, and user interactions?
The skill provides an overview and references to detailed patterns. Full coverage of GeoJSON sources, custom layers, and feature interactions is in the bundled reference files (custom-data.md, camera-styles.md, and interactions.md).
What version of Mapbox Maps SDK does this skill target?
Mapbox Maps SDK v11 for Android, with the most recent tested version being 11.18.1.

Generated from the current SKILL.md. These answers refresh after source changes.