# Quickstart

> Canonical URL: https://docs.mountaya.com/en/sdks/kotlin/quickstart/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Show a Mountaya map with the Tour du Mont-Blanc on it in a Jetpack Compose Android app.

A Jetpack Compose app for Android that shows a topographic map and draws the Tour du Mont-Blanc on it.

## Before you start

You need Android Studio with Kotlin 2.4 or newer, and an emulator or device on Android 7.0 (API 24) or later. You also need a publishable key with the `tiles` and `publishing` scopes, from **Organization → API keys** in the [Mountaya app](https://app.mountaya.com/api-keys).

## Install

Create an **Empty Activity** project in Android Studio. In the app's `build.gradle.kts`, set `compileSdk = 37` and add the modules:

```kotlin
dependencies {
    implementation("com.mountaya:mountaya-client:0.1.0")
    implementation("com.mountaya:mountaya-geo:0.1.0")
    implementation("com.mountaya:mountaya-elements:0.1.0")
}
```

Declare `android.permission.INTERNET` in `AndroidManifest.xml`.

## Add your key

Put the key in an `.env` file beside the app's build script, and list it in `.gitignore`:

```text
MOUNTAYA_PUBLISHABLE_KEY=pk_your_publishable_key
```

Hand it to the app as a `BuildConfig` field, read from the environment, else from `.env`:

```kotlin
val dotEnv =
    file(".env").takeIf { it.isFile }?.readLines().orEmpty()
        .filter { "=" in it && !it.startsWith("#") }
        .associate { it.substringBefore('=').trim() to it.substringAfter('=').trim() }
val key = System.getenv("MOUNTAYA_PUBLISHABLE_KEY") ?: dotEnv["MOUNTAYA_PUBLISHABLE_KEY"].orEmpty()

android {
    buildFeatures { buildConfig = true }
    defaultConfig { buildConfigField("String", "MOUNTAYA_PUBLISHABLE_KEY", "\"$key\"") }
}
```

## Show the map

Replace `MainActivity.kt` with this:

```kotlin
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import com.mountaya.client.Credential
import com.mountaya.client.Mountaya
import com.mountaya.elements.MapEngine
import com.mountaya.elements.MapView

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent { TrailMap() }
    }
}

@Composable
fun TrailMap() {
    // One client and one map engine for the screen's lifetime.
    val mountaya = remember { Mountaya(Credential.Publishable(BuildConfig.MOUNTAYA_PUBLISHABLE_KEY)) }
    val map = remember { MapEngine(mountaya) }
    DisposableEffect(map) {
        onDispose {
            map.close()
            mountaya.close()
        }
    }
    LaunchedEffect(map) { map.setTerrain() }
    MapView(map)
}
```

## Draw an itinerary

Replace `TrailMap` with this version. It draws the Tour du Mont-Blanc and fits the camera to it:

```kotlin
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import com.mountaya.client.Credential
import com.mountaya.client.Mountaya
import com.mountaya.elements.CameraFit
import com.mountaya.elements.MapEngine
import com.mountaya.elements.MapView
import com.mountaya.geo.PixelPadding

@Composable
fun TrailMap() {
    val mountaya = remember { Mountaya(Credential.Publishable(BuildConfig.MOUNTAYA_PUBLISHABLE_KEY)) }
    val map = remember { MapEngine(mountaya) }
    DisposableEffect(map) {
        onDispose {
            map.close()
            mountaya.close()
        }
    }
    LaunchedEffect(map) {
        map.setTerrain()
        map.setItinerary("0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21", fit = CameraFit(padding = PixelPadding(48.0)))
    }
    MapView(map)
}
```

## Run it

Run the app on an emulator or a device:

```bash
./gradlew installDebug
```

The map opens on the Tour du Mont-Blanc, with the Mountaya watermark in its top-left corner.

- The sample app Trail, under `examples/trail` in the SDK repository, is the complete version of this quickstart: controls, search, the profile, the tables and navigation. Copy `examples/trail/.env.example` to `examples/trail/.env`, then `./gradlew -p examples/trail installDebug`.
- `setTerrain()` shows the first terrain of the Tile API's catalogue, light until `setTerrainVariant(TileSchema.TerrainVariant.Dark)`. `setTerrain("<slug>")` names another.
- `setItinerary(id, fit)` draws one itinerary by id in its own slot and answers whether it drew. A later call replaces it, and one that answers after a later call answers `false`. Cancelling its coroutine, as `LaunchedEffect` does when it leaves the composition, withdraws it. `clearItinerary()` removes it.
- `MapEngine` and `MapView` need the key's `tiles` scope; a published itinerary needs `publishing`. A refused key shows as `map.state.value.isAccessRequired` and a `MapEvent.AccessRefused`; see [show a map](https://docs.mountaya.com/en/sdks/kotlin/map.md#errors).
- Every request MapLibre makes for the map (style, tiles, sprites, glyphs) carries the client's credential, its language and `X-Mountaya-Client`, and only to the Tile API's host, through interceptors on MapLibre's process-wide `OkHttpClient`.
- The watermark shows unless the organization holds white label; the map reads that once per key and Map Studio API origin.
- `MapView` is Android only. The quickstart's app needs the Compose compiler plugin, which Android Studio's Empty Activity template already applies, and `androidx.activity:activity-compose`, which it already declares.

## Next steps

- [Show a map](https://docs.mountaya.com/en/sdks/kotlin/map.md): The camera, clicks, layers and waypoints.
- [Controls and panels](https://docs.mountaya.com/en/sdks/kotlin/controls.md): Zoom, layers, points of interest and units.
