Get started
Kotlin SDK
Get started

Install and set up

Install and set up

The modules are on Maven Central under com.mountaya, at one version. Add the ones your build uses.

Install the packages

An Android app that shows a map adds the client and the elements:

dependencies {
    implementation("com.mountaya:mountaya-client:0.1.0")
    implementation("com.mountaya:mountaya-elements:0.1.0")
    // Turn-by-turn navigation, Android only.
    implementation("com.mountaya:mountaya-navigation:0.1.0")
}

A JVM server adds the admin package, which brings the client with it:

dependencies {
    implementation("com.mountaya:mountaya-admin:0.1.0")
}

Keep mavenCentral() among the build's repositories. mountaya-geo comes with mountaya-elements; add it alone for the rules without a map.

Set up the platform

On Android, apply the Compose compiler plugin and meet the floors:

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig {
        minSdk = 24
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
}

Declare the network in AndroidManifest.xml, and the location permissions if the app locates the reader or navigates:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

In a Kotlin Multiplatform project, the four multiplatform modules go in commonMain, and navigation in androidMain:

kotlin {
    sourceSets {
        commonMain.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")
        }
        androidMain.dependencies {
            implementation("com.mountaya:mountaya-navigation:0.1.0")
        }
    }
}

Add your key

Keep the publishable key out of source control. Put it in an .env file beside the app's build script, listed in .gitignore:

MOUNTAYA_PUBLISHABLE_KEY=pk_your_publishable_key
MOUNTAYA_SESSION_URL=http://10.0.2.2:8787/session

Read it in Gradle from the environment, else from .env, the way the SDK's sample app Trail does, into BuildConfig:

val dotEnv =
    file(".env").takeIf { it.isFile }?.readLines().orEmpty()
        .filter { "=" in it && !it.startsWith("#") }
        .associate { it.substringBefore('=').trim() to it.substringAfter('=').trim() }

fun setting(name: String): String = System.getenv(name) ?: dotEnv[name].orEmpty()

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

The app then builds its client from BuildConfig:

import com.mountaya.client.Credential
import com.mountaya.client.Mountaya

fun appClient(): Mountaya = Mountaya(Credential.Publishable(BuildConfig.MOUNTAYA_PUBLISHABLE_KEY))

A server reads its keys from environment variables:

import com.mountaya.client.Credential
import com.mountaya.client.Mountaya
import com.mountaya.client.invoke

val server = Mountaya(Credential.Secret(System.getenv("MOUNTAYA_SECRET_KEY").orEmpty()))
println(server.baseUrls)
server.close()

Create keys under Organization → API keys in the Mountaya app.

Import the right package

Each module's API is one package named after it. Import the names you use:

ModulePackageMain names
mountaya-clientcom.mountaya.clientMountaya, Credential, SessionTokenEngine, the exceptions
mountaya-admincom.mountaya.adminadmin, constructWebhookEvent
mountaya-geocom.mountaya.geoformatDistance, SearchEngine, RouteFollowingEngine
mountaya-navigationcom.mountaya.navigationDeviceNavigationEngine, SpeechNavigationVoice
mountaya-elementscom.mountaya.elementsMapEngine, MapView, MapControls, ItineraryProfile

The secret key and the admin package are for servers only. An app imports neither.

Next steps

Last updated