Android quickstart (Kotlin)

Get a key

In Atlas Studio, create an app key with these features: Routes (core_routing), Navigation (navigation) and Maps (map_tiles). Add your package name and the SHA-256 of each certificate that signs your app: ./gradlew signingReport prints them, and the debug and release builds are signed with different certificates, so list both (a build signed with one the key doesn't list fails with app_not_allowed). The secret is shown once: keep it out of source control (for example a local.properties entry read into BuildConfig). Studio's code sample needs only the key: the configuration defaults to the Atlas service and map viewer (below).

Install

Two artifacts: dev.meridianatlas:atlas-core (pure Kotlin sessions, no Android dependencies) and dev.meridianatlas:atlas-android (the Android host, map view, GPS service and offline jobs; it brings in the core). Until they're on a registry, add the release's android/maven folder as a repository:

Kotlin
// settings.gradle.kts
dependencyResolutionManagement { repositories { google(); mavenCentral(); maven { url = uri("path/to/release/android/maven") } } }
// app/build.gradle.kts
dependencies { implementation("dev.meridianatlas:atlas-android:0.1.0-rc.6") }

Android 8.0 (API 26) or later.

Configure the key

Make one AtlasConfiguration and give it to every client, the navigation host and the map:

Kotlin
val atlas = AtlasConfiguration(context, apiKey)
val routes = AtlasRoutes(atlas)
val host = AtlasNavigation(atlas, listener = listener)  // reroutes and registers its legs itself (below)
val map = AtlasMapView(context, atlas)                    // the viewer gets the key
// AtlasMultiStop, AtlasRouteMatrix, AtlasPlaces, AtlasTraffic, AtlasNavigationLegs and AtlasRoads too

The configuration defaults to the Atlas service at https://api.meridianatlas.dev and the map viewer at https://maps.meridianatlas.dev/v1, so this needs only your key. That domain isn't live yet: until it is, beta partners pass the two addresses Meridian gave them:

Kotlin
val atlas = AtlasConfiguration(context, apiKey, "https://your-atlas-host", viewerUrl = "https://your-atlas-viewer")

(ATLAS_DEFAULT_BASE_URL and ATLAS_DEFAULT_VIEWER_URL name the defaults.) URLs must use HTTPS; plain HTTP works only when the app is debuggable, to this device (localhost, 127.0.0.1) or the emulator's host (10.0.2.2). Android also refuses plain HTTP unless your debug build's network security config allows cleartext to that host (the request then fails with network_error). timeoutMillis (default 30000) applies to each request. The configuration reads your app's package name and the SHA-256 of its signing certificate from context once, and every request sends them (Atlas-App, Atlas-App-Cert), so an app key made in Atlas Studio for that package and certificate works; an app key used from an app it doesn't list fails with app_not_allowed. With signing key rotation the current certificate is sent; with several signers, list each signer's certificate on the key. The older constructors, AtlasRoutes(baseUrl, apiKey) and the rest, still work but send no app (use them with server keys); every sample below takes the configuration.

Getting a route

Kotlin
val routes = AtlasRoutes(atlas) // atlas: from "Configure the key"
val route = routes.route(AtlasCoordinate(-2.2511, 53.4747), AtlasCoordinate(-2.246, 53.4837)) // blocking: off the main thread
// route.guidance: the steps to show and speak; route.plan: what begin() takes
// route.speedSections: the speed limits along it

Pass departureTime = Instant.parse("2026-12-01T08:00:00Z") to plan a later journey, trafficAware = true to allow for traffic, and approach = AtlasApproach.CURB to arrive with the destination on the driver's side of the road (the left in the UK). The route's plan keeps these (route.plan.options), so its reroutes are asked for the same way. Every client calls the service with HttpURLConnection (no other dependencies; redirects refused, so the key never follows one). The calls block: make them off the main thread, for example in withContext(Dispatchers.IO). Pass transport to use your own HTTP client. A failure is an AtlasException (see Errors); route_unresolved means there is no route between those points.

Route guidance with the Android host

Kotlin
val host = AtlasNavigation(atlas, listener = object : AtlasNavigationListener {
    override fun onUpdate(update: AtlasNavigationUpdate) { render(update.snapshot) }
    override fun onEffect(effect: AtlasNavigationEffect) { if (effect is AtlasNavigationEffect.Arrived) showArrival() }
    // The host rerouted: show the new route, and guide by its steps from now on.
    override fun onRerouted(route: AtlasRoute, request: AtlasNavigationEffect.RequestReroute) { map.showRoute(route) }
})
host.begin(route.plan)   // the AtlasRoute from routes.route(...)
// For each fused-location fix:
host.ingest(AtlasPositionSample(lon, lat, timeMs, accuracyM, speedMps, bearing, bearingAccuracy))
// About once a second, so GPS loss is noticed:
host.tick(System.currentTimeMillis())
// When the screen goes for good:
host.stop()

The listener is called on the main thread (pass callbackExecutor for another), so it can update views directly. Through a tunnel the host estimates progress from the last speed: snapshot.positionEstimated is true then, so show the position as estimated.

Rerouting

Made with a configuration, the host reroutes by itself. When the car leaves the route, it fetches a new one on a background thread: from where the car is, facing the way it is going, to the destination (on a multi-stop route, the next stop not yet reached), asked the way the route was (its plan's options: profile, traffic, side of the road, and a departure time moved on by the time guidance has run). Guidance keeps the old route until the new one arrives. Your app only shows the new route: onRerouted(route, request) brings it, just after the RouteReplaced effect.

It doesn't reroute a car crawling off the route (a car park, a forecourt, a queue) unless it has turned round. For apps that show what is happening, the effects say:

  • RequestReroute: a route is being fetched (phase is REROUTING).
  • RouteReplaced: the new route is in use.
  • RerouteFailed: the fetch failed (reason is the error's code, or no_answer after 20 seconds). The old route is kept, and the host asks again at retryAtMs: after 3 seconds, then 6, 12 and so on, up to a minute.
  • RerouteCancelled: the car came back to the route (reason is back_on_route), so the fetch was cancelled.
  • RerouteDeferred: no connection (offline), or waiting before asking again (backoff). Call host.setConnectivity(false, nowMs) when the device goes offline, and reroutes wait instead.

Answering reroutes yourself

Pass a transport to use your own routing: AtlasNavigation(atlas, transport, listener), or AtlasNavigation(transport, listener) without a configuration (the host then contacts no server). The host keeps request identity, cancellation of stale requests and atomic route replacement:

Kotlin
val routes = AtlasRoutes(atlas)
val background = Executors.newSingleThreadExecutor()
val main = Handler(Looper.getMainLooper())
val transport = AtlasRerouteTransport { request, completion ->
    // The transport is called on the thread that gave the fix (usually the main one), and
    // AtlasRoutes blocks: fetch on a background thread, then answer on the main thread.
    val task = background.submit {
        val result = runCatching { routes.reroute(request, route.plan.options).plan } // from the car, facing its way
        main.post { completion(result) }               // a failure: Atlas backs off and asks again
    }
    AtlasRerouteCall { task.cancel(true) } // Atlas no longer needs it (the car rejoined the route)
}

Call completion with a failure when the fetch fails: an AtlasException's code goes on RerouteFailed, and Atlas backs off and asks again. A request with no answer after 20 seconds counts as failed, and one the car no longer needs (it rejoined the route) is cancelled; an answer to it after that is ignored. onRerouted isn't called: you have the route. Coroutines work as well: launch withContext(Dispatchers.IO) { routes.reroute(request).plan } in a scope on Dispatchers.Main, call completion with the result, and return AtlasRerouteCall { job.cancel() }. Shut background down when the screen goes.

Guidance with the screen off

ForegroundLocationSource runs GPS with a location foreground service, so guidance carries on with the screen off or the app in the background:

Kotlin
val gps = ForegroundLocationSource(context)
gps.checkAvailable()                         // throws location_permission_required or location_accuracy_reduced
gps.start { sample -> host.ingest(sample) }  // when navigation begins
gps.stop()                                       // when it ends

The SDK's manifest declares the service and the location, foreground-service, notification and network-state permissions. Your app still asks the user for ACCESS_FINE_LOCATION before starting, and on Android 13+ for POST_NOTIFICATIONS so the notification shows. Without location permission the service isn't started (Android refuses it): gps.checkAvailable() throws AtlasPluginException with code location_permission_required, and with only approximate location location_accuracy_reduced (too coarse to navigate by), each with a message saying what to ask for. React Native and Flutter report them the same way from begin. Stopping straight after starting is safe. The notification says "Navigating"; to translate or rebrand it, define atlas_navigation_notification_title and atlas_navigation_channel_name in your app's strings.xml. Its small icon is the SDK's monochrome arrow; to use your own (white on transparent):

XML
<!-- AndroidManifest.xml, inside <application> -->
<meta-data android:name="dev.meridianatlas.notification_icon" android:resource="@drawable/ic_navigation" />

Turn-by-turn guidance is charged per leg: one leg is guidance to one destination, and the reroutes on the way are included (the key needs the navigation feature). Made with the configuration, the host does this itself:

Kotlin
val host = AtlasNavigation(atlas, listener = object : AtlasNavigationListener {
    override fun onError(error: AtlasException) { log(error) }   // leg_registration_failed: guidance carries on
})
host.begin(route.plan)   // registers the leg to the route's end, in the background
host.stop()              // ends the leg (on arrival it ends itself)
  • begin registers the leg on a background thread; guidance never waits for it. Beginning again to the same destination (within 50 m) keeps the leg; a new destination ends it and starts another. host.legId is the leg, once registered.
  • Each RequestReroute (to the listener, and to a transport) carries legId, and the host's reroutes send it (so does routes.reroute(request) in a transport), so a reroute costs nothing more. A leg includes 50 reroutes: after that, or if the service refuses the leg, the host reroutes without it, charged as a route, and onError gets leg_invalid once. A reroute asked for before the leg is registered goes without one, and is charged as a route.
  • A failure that may pass (no connection, a timeout, rate_limit, a 5xx) is tried again after 1, 2, 4, 8 and 16 seconds, with the same Idempotency-Key, so the leg is charged once. If it still can't be registered (or the key is refused: capability, status and the message say why), AtlasNavigationListener.onError gets an AtlasException with code leg_registration_failed, once, on the callback executor. Guidance carries on, and its reroutes are charged as routes.
  • Arrival ends the leg (ARRIVED), and so does stop() (CANCELLED).
  • httpTransport is for tests or your own networking.

Without a configuration the host contacts no server; do the same by hand:

Kotlin
val legs = AtlasNavigationLegs(atlas)
val leg = legs.start(route.coordinates.last())                         // when guidance starts
val replacement = routes.reroute(request, legId = leg.legId)          // in the host's transport: included in the leg
legs.end(leg.legId, AtlasNavigationLegEndReason.ARRIVED)               // on arrival (CANCELLED when the driver stops)

Pass reroute the original route's options (routes.reroute(request, route.plan.options, leg.legId)) to keep them. A reroute must keep the leg's destination (within 50 m): a new destination is a new leg, and so is each stop of a multi-stop route (the host does this itself, see Multi-stop routes; by hand, start one with the stop's point on the route when the driver sets off for it). A leg lasts 24 hours. A reroute with a leg that has ended or expired fails with leg_invalid, and one to somewhere else with leg_destination_mismatch: start a new leg. Asking again for the same RequestReroute after a timeout or lost connection reuses its Idempotency-Key, so a request that did reach the service counts once.

Showing the map

AtlasMapView is the Atlas 3D map in a WebView, from the Atlas viewer at the configuration's viewerUrl. The viewer gets the configuration's key for its scenery, in the page, never in its URL. Show it the route, then give it each snapshot to move the car, estimated progress through a tunnel included:

Kotlin
val map = AtlasMapView(context, atlas, presentation = AtlasMapPresentation(navigationUI = true).toViewerParameters())
map.onError = { code, message -> showStatus("Map: $message") }
map.onWarning = { code, active, message -> mapNotice.visibility = if (active) View.VISIBLE else View.GONE }
container.addView(map)
map.showRoute(route)                  // the AtlasRoute whose plan you began; after a reroute, onRerouted's (swapped in place)
// in AtlasNavigationListener.onUpdate:
map.update(update.snapshot)
// when the screen goes for good:
map.destroy()

AtlasMapView(context, atlas, viewerBaseUrl) loads the viewerBaseUrl you pass instead of the configuration's viewerUrl. AtlasMapView(context, viewerBaseUrl) still works and sends no key.

onError says the map couldn't start or has stopped, with a code: viewer_unavailable (the viewer page didn't load: check viewerUrl and the connection), scene_unavailable (no scenery came for that place after every try), viewer_error, context_lost (it lost its graphics context and three reloads didn't bring it back), or route_too_large, invalid_route or unsupported_contract (the viewer refused what it was shown). onWarning is a problem the map carries on through (map_detail_unavailable, context_lost, runtime_error, quality_reduced), with active true when it starts and false when it clears. A lost graphics context is recovered by reloading the map, which keeps what it was shown.

Show it the AtlasRoute (or an AtlasMultiStopRoute), not only its plan: the map then gets the route's guidance, so the route line moves into the lane each junction needs, and its speed limits. showRoute(route.plan) still works and shows only the line. navigationUI = true shows the built-in Meridian guidance panels (manoeuvre, lanes, camera alerts, and the speed with the limit, red when over it); it is off by default, for apps that draw their own. Its banner shows the route's own words ("At the traffic lights, turn right onto Ormskirk Road"), the sign at a fork and a roundabout's exit.

The panels also show:

  • Trip progress: the arrival time, time left and distance left. On a multi-stop trip they show the next stop ("Stop 2 of 4") and the destination.
  • Recentre: the driver can pan and pinch the map, and Recentre brings the camera back to the car, at the camera's own distance, tilt and heading.
  • Overview: the whole remaining route (the car, each stop left and the destination), flat and north-up, clear of the panels. Guidance carries on, and Recentre comes back.
  • Mute: the voice's mute button.
  • The arrival card: at each stop it offers Next stop and End; at the destination, End.

Name the places, and pass the driver's choices on:

Kotlin
map.showRoute(route, destination = AtlasMapPlace("Interact CC Wigan", "Wallgate, Wigan WN1 1BA"))
// A multi-stop trip: map.showRoute(trip, stops = mapOf("tesco" to AtlasMapPlace("Tesco Pemberton")))
map.voice = voice // the AtlasVoice speaking your announcements: the mute button mutes and unmutes it
map.onArrivalAction = { action -> if (action is AtlasArrivalAction.End) navigation.stop() }

With map.voice set, the mute button and the voice follow each other: there is nothing more to write, and voice.isMuted = true from your own settings shows on the button. If you speak with something other than AtlasVoice, pass the taps on yourself: map.onVoiceMutedChanged = { muted -> myVoice.mute(muted) }. map.isVoiceMuted is the mute state. Set it to show your app's own setting on the button. map.recentre() and onFollowingChanged do what the button does, for your own controls; map.showOverview(), isOverview and onOverviewChanged do the same for the overview. AtlasMapPresentation(navigationPanels = ...) turns panels off one by one (a set of AtlasNavigationPanel). Without RECENTRE, the map doesn't move under the driver's fingers, and the overview button doesn't show. AtlasMapPresentation(autoRecentreAfterSeconds = 10.0) brings the camera back to the car by itself 10 seconds after the driver last moved the map or opened the overview (2 to 600 seconds; off by default).

Lay the map out edge to edge (every app is, on Android 15 and later): the map view tells the panels what the status bar, the camera's cut-out and the navigation bar cover, upright and on its side, and their text follows the system's font size (up to 1.5 times). If your own views cover part of the map, say how many dp at each edge, measured from the map's edges, and the panels and the car keep clear of them too: map.setInsets(0.0, 0.0, sheetHeightDp, 0.0) (top, left, bottom, right). Call it again when your views move.

quality sets how much the map spends on each frame: AtlasMapQuality.AUTO (the default) starts from what the device says about itself and steps down a tier when frames stay slow (a quality_reduced warning); HIGH, BALANCED and LOW hold one tier. It goes to the viewer with the other presentation parameters. map.quality says which tier the map started at, once it is ready.

In free drive, showPosition at the car's first matched point and pass each free-drive snapshot to map.update(snapshot); the car follows the road it is matched to, and the map shows the speed limit there.

The SDK declares the INTERNET permission. A plain-HTTP (development) viewer needs a network security config allowing it.

Speaking the guidance

Atlas decides what to say and when. Any update can carry an announcement in update.announcements, and AtlasNavigationListener.onAnnouncement gets each one: "In 300 yards, turn left onto Deansgate", then "Turn left now".

  • Where they come from: the route's guidance. route.plan carries it, so a route from AtlasRoutes or AtlasMultiStop is announced. A hand-made AtlasRoutePlan without guidance is guided in silence.
  • When: warnings come further ahead on faster roads, and close manoeuvres are joined ("…, then turn left"). Nothing is said while phase isn't ON_ROUTE, and after a reroute (the session's own, or yours) the new route is announced with nothing said twice. Each stop of a multi-stop route gets its own arrival.
  • Road numbers: written the way they are said ("the A five-eighty", "junction 19"), so any speech engine says them the British way.

To have Atlas speak them, use the opt-in AtlasVoice:

Kotlin
val voice = AtlasVoice(context)   // the best installed British voice
voice.listener = object : AtlasVoiceListener {
    override fun onWillSpeak(announcement: AtlasAnnouncement) { /* request transient focus that may duck */ }
    override fun onDidSpeak(announcement: AtlasAnnouncement, interrupted: Boolean, speaking: Boolean) {
        if (!speaking) { /* abandon it */ }
    }
}
// in AtlasNavigationListener.onUpdate: voice.handle(update)
// when the screen goes for good: voice.shutdown()
  • Voices:
    • voice.voices(AtlasVoiceFilter(locale = "en-GB", minimumQuality = "enhanced")) lists the installed voices, best first.
    • Choose one with voice.selectedVoiceId; voice.preview(voiceId = …) says a sample.
    • A network voice is used only while the device is online, and a voice on the device otherwise.
    • Google's British voices may need a download: Settings › System › Languages › Text-to-speech output.
  • Audio focus stays yours: AtlasVoice requests none. Its speech is marked USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, so it reaches the car's speakers. Request transient focus that lets other audio duck (AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK) in onWillSpeak, and release it in onDidSpeak when nothing more is to be said.
  • Rules: a more urgent announcement cuts the current one short, and a less urgent one waits for it. A pause drops whatever was waiting. An engine that never finishes a prompt is cut short. Also isMuted and stop().
  • Your own voice: AtlasVoice(output) takes an AtlasVoiceOutput (speak(text, ssml, completion), stop()), for example a cloud neural voice. Or skip AtlasVoice and speak each announcement's text yourself.

AtlasVoice is in dev.meridianatlas.android; AtlasAnnouncement is in dev.meridianatlas.

Testing in the emulator

  • A drive: in the emulator's Extended controls > Location, plan a route or load a GPX or KML file and play it; or send fixes from a terminal, one at a time, with adb emu geo fix <longitude> <latitude>.
  • Allow location first, in the app's own prompt or in Settings.
  • The service on your computer is http://10.0.2.2:<port> from the emulator (a debug build, with the network security config above).
  • In tests, pass AtlasPositionSamples to host.ingest and times of your own to tick; no emulator needed.

Using the core session directly

Kotlin
val session = AtlasNavigationSession(AtlasNavigationConfig.SDK) // as the host runs it: dead reckoning through tunnels
session.begin(AtlasRoutePlan("route-1", ATLAS_ONLINE_MAP_VERSION, listOf(AtlasCoordinate(-2.8, 53.55), AtlasCoordinate(-2.8, 53.553))))
val update = session.ingest(AtlasPositionFix(AtlasCoordinate(lon, lat), timeMs, accuracyM, speedMps, bearing, bearingAccuracy), nowMs)
for (effect in update.effects) when (effect) {
    is AtlasNavigationEffect.RequestReroute -> { /* fetch a route, then session.completeReroute(effect.requestId, nowMs, newRoute); null if it failed */ }
    is AtlasNavigationEffect.Arrived -> { /* show arrival */ }
    else -> {}
}

Free drive (no destination)

Kotlin
val freeDrive = AtlasFreeDrive()
freeDrive.begin()
fun handle(update: AtlasFreeDriveUpdate) {
    roadLabel.text = update.snapshot.roadName
    limitSign.show(update.snapshot.speedLimit)          // AtlasSpeedLimit(30, "mph")
    for (effect in update.effects) if (effect is AtlasFreeDriveEffect.RoadsNeeded)
        handle(freeDrive.setRoads(effect.centre, effect.radiusM, loadRoads(effect.centre, effect.radiusM)))
}
handle(freeDrive.ingest(AtlasPositionFix(AtlasCoordinate(lon, lat), timeMs, accuracyM, speedMps, bearing, bearingAccuracy), nowMs))

Loading roads

AtlasRoads answers RoadsNeeded from the Atlas service (the key needs the road_attributes feature; each answer is one unit; blocking, so off the main thread):

Kotlin
val roads = AtlasRoads(atlas)
val nearby = roads.nearby(effect.centre, effect.radiusM)
freeDrive.setRoads(nearby.centre, nearby.radiusM, nearby.roads)

Each AtlasRoad has name, ref (A56), highway, maxspeed ("30 mph"; null when unknown, never a guess), maxspeedForward / maxspeedBackward and oneway, as OpenStreetMap tags them. radiusM is 50 to 2000 metres.

Places

Search as the user types, then fetch the place they pick. Use one sessionToken (16 or more characters) from the first keystroke to the pick. fields says which fields to return; the common ones come back typed, and raw has the rest.

Kotlin
val places = AtlasPlaces(atlas)
val suggestions = places.autocomplete(mapOf("input" to typed, "sessionToken" to sessionToken)).suggestions
val picked = suggestions.first { it.placeId != null } // a query suggestion has no placeId
val place = places.place(picked.placeId!!, listOf("id", "displayName", "formattedAddress", "location"), sessionToken = sessionToken)
// place.displayName, place.formattedAddress, place.location (an AtlasCoordinate), place.types, place.raw

searchText(mapOf("textQuery" to …), fields) and searchNearby return places and nextPageToken; photo(placeId, photoId) returns the image bytes.

Traffic

The delay on a route you already have, and how fast each stretch is moving:

Kotlin
val traffic = AtlasTraffic(atlas)
val advisory = traffic.routeAdvisory(request) // request.requestId: a new UUID per advisory
// advisory.delaySeconds, advisory.speedReadingIntervals[i].state ("normal", "slow", "traffic_jam", "unknown")

Route matrix

Distances and driving times from up to 25 origins to up to 25 destinations:

Kotlin
val matrix = AtlasRouteMatrix(atlas)
val result = matrix.calculate(AtlasRouteMatrixRequest("job-17", drivers, listOf(job)))
val seconds = result.cell("van-1", "job")?.durationSeconds // null when no route was found

Multi-stop routes

One route through 2 to 64 stops in the order given, with a leg per pair:

Kotlin
val multiStop = AtlasMultiStop(atlas)
var run = multiStop.route(AtlasMultiStopRequest("run-17", stops)) // stops: AtlasRouteStop(id, coordinate, serviceSeconds)
// run.legs[i].distanceMetres, .durationSeconds, .guidance; run.plan drives the whole trip, stop by stop
map.showRoute(run)
host.begin(run.plan)
// In onRerouted, the host has rerouted to the next stop (request.stopId); show the whole trip:
//   run = run.rerouted(request, route); map.showRoute(run)
  • Arrivals. At each stop before the last the listener gets StopArrived(stopId, legIndex) and guidance carries on to the next stop; at the last, Arrived (with its stopId). LegStarted says the car has left a stop (more than 50 m away, or off the route). snapshot.legIndex, legCount, nextStopId and legRemainingM say which leg is being driven.
  • Reroutes go to the next stop not yet reached, never back to one reached and never straight to the end; a car that drives past a stop without reaching it is rerouted back to it. The host keeps the rest of the trip after that stop; run.rerouted(request, route) gives the whole trip, for the map. Answering reroutes yourself, the route to that stop is enough.
  • Billing. The route is n − 1 Routes. With a configuration, guiding it is one Navigation leg per stop: the first at begin, each later one when the car leaves the stop before it, each ended at its stop. A run stopped at a stop is never charged the next leg, and the reroutes are free.

Android Auto

AtlasCar (dev.meridianatlas.android.car) shows the map, route choices and guidance on Android Auto, on the Car App Library's navigation template. Add androidx.car.app:app and a car app service in the navigation category, give AtlasCar the routes you guide along and each AtlasNavigationUpdate, and return car.createSession() from the service. AtlasRouteSimulator drives the session along the route without moving, for testing and for Google Play's reviewers. The manifest and the review instructions are in the CarPlay and Android Auto guide (docs/sdk/car-screens.md).

Errors

Every service client throws AtlasException, with the same code on every Atlas SDK:

CodeMeaning
invalid_requestThe request was refused as malformed (also thrown before sending)
missing_api_keyThe configuration's key is empty (thrown before sending)
invalid_api_keyThe key is wrong, revoked or expired: copy it again from Atlas Studio, or make a new one
capability_requiredThe key doesn't have this feature; capability names it (turn it on for the key)
app_not_allowedThe key is limited to other apps: make the client from the configuration (it sends your package and certificate), and list the SHA-256 of every certificate that signs the build, debug and release, on the key
billing_inactive, usage_policy_required, usage_allowance_exhaustedThe account can't be charged for this call
rate_limitToo many requests; retryAfterSeconds says when to try again
outside_coverageThe origin or destination is outside the area Atlas routes (the UK at launch)
route_unresolvedNo route between those points
leg_invalid, leg_destination_mismatch, leg_not_foundThe navigation leg can't be used (ended, expired, unknown, had its 50 reroutes, or a new destination): start a new one. To AtlasNavigationListener.onError, once: the host's reroutes go on without the leg, charged as routes
leg_registration_failedTo AtlasNavigationListener.onError: the host couldn't register its leg; guidance carries on, and its reroutes are charged as routes
wrong_service_addressSomething answered at the service address, but not the Atlas service: check baseUrl
request_timeout, network_errorNo answer in time, or no connection (or nothing at the service address)
invalid_responseThe answer couldn't be read (a wrong service address, or a network that needs a sign-in page)
service_errorAnything else; status has the HTTP status

isRetryable says whether trying the same call again later can work (no connection, a timeout, a rate limit, a service error with a status of 500 or more), and retryAfterSeconds when the service said. The message says what to fix and ends with a link to the code's entry in Errors, which has every code. requestId is the service's id for the request, to quote to support.

Kotlin
try {
    routes.route(origin, destination)   // off the main thread
} catch (error: AtlasException) {
    if (error.code == "capability_required") showStatus("Turn on ${error.capability} for this key")
    else if (error.isRetryable) showStatus("No connection: try again")  // error.retryAfterSeconds, when the service said
    else showStatus(error.message ?: error.code)                         // says what to fix, with a link
}

Each client sends your key as X-Atlas-Key and the SDK version as Atlas-Client: android/0.1.0-rc.6. Calls that are billed per request send an Idempotency-Key; pass idempotencyKey (a UUID) to make a retry count once.

Threading

The core sessions (AtlasNavigationSession, AtlasFreeDrive) are not thread-safe: call them from one thread or dispatcher. AtlasNavigation's methods are synchronized, so fixes, ticks, connectivity and reroute completions may come from any thread; its listener is called on the main thread, in order (or on the callbackExecutor you pass), and its navigation-leg calls and reroute fetches run on SDK background threads. AtlasMapView can be called from any thread and moves the work onto the main thread itself. The service clients block, refuse to run on the main thread, and can be shared between threads.

Proposal · draft