# Geo without a map

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

Measure and format distances, build an elevation series, read the terrain at a point and write values in the reader's units, with mountaya-geo and no network.

`mountaya-geo` holds Mountaya's rules as plain functions: no network, no renderer. They answer the same numbers and words in every Mountaya SDK.

## Measure and format distances

A position is `[longitude, latitude]`, as the API writes it:

```kotlin
import com.mountaya.geo.UnitPreferences
import com.mountaya.geo.formatDistance
import com.mountaya.geo.formatLngLat
import com.mountaya.geo.haversineMeters
import com.mountaya.geo.routeLengthMeters

fun measure() {
    val chamonix = listOf(6.8712, 45.9231)
    val argentiere = listOf(6.9271, 45.9822)
    val line = listOf(chamonix, listOf(6.9001, 45.9530), argentiere)
    val units = UnitPreferences(language = "fr-FR")
    println(formatDistance(routeLengthMeters(line), units))
    println("${haversineMeters(chamonix, argentiere)} m from ${formatLngLat(chamonix)}")
}
```

- Every rule is a top-level function of `com.mountaya.geo`, named as the other SDKs name it, proven by the contract's shared test cases on the jvm, the iOS simulator and an Android emulator.
- A rule handed a position that names no place answers rather than throws: a distance is `NaN`, a printed position `null`.
- Geodesy and route measures: `haversineMeters`, `routeLengthMeters`, `cumulativeMeters`, `bearingDegrees`, `positionAtMeters`, `distanceToSegment`, `metersToRoute`, `wrapLongitude`, `longitudeDelta`. The camera's: `boundsOf`, `cameraForBounds`, `boundsWithPixelPadding`, `zoomToAltitude`, `altitudeToZoom`, `groundMetersPerPixel`.
- Conversions: `convertLength(value, from, to)` with `LengthUnit` (`Meter`, `Kilometer`, `Centimeter`, `Mile`, `Foot`, `Inch`), `convertSpeed`, `convertDuration`, `convertTemperature`, `convertAngle`, `convertDataSize`, `convertProportion`, `convertSlope` (`SlopeUnit`).
- `mountaya-geo` depends on `mountaya-client` with `api` for its types (Kotlin has no type-only dependency); it never calls the network.

## Build an elevation series

The figures an elevation profile draws come from the itinerary's geometry:

```kotlin
import com.mountaya.client.Mountaya
import com.mountaya.geo.ResolvedItinerary
import com.mountaya.geo.UnitPreferences
import com.mountaya.geo.buildElevationSeries
import com.mountaya.geo.formatDistance
import com.mountaya.geo.formatElevation
import com.mountaya.geo.profileTotals

suspend fun tourFigures(mountaya: Mountaya) {
    val itinerary = mountaya.studio.itineraries.getItinerary("0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21").data
    val series = buildElevationSeries(ResolvedItinerary(itinerary).geometry)
    val totals = profileTotals(series)
    val units = UnitPreferences("en")
    println("${formatDistance(totals.distance, units)}, +${formatElevation(totals.ascent, units)}")
}
```

- `buildElevationSeries(geometry, maxPoints)` takes a `LineString`, a `MultiLineString`, a `GeometryCollection`, a `Feature` or a `FeatureCollection`: every line shares one distance axis, and the elevation is each position's third coordinate. An `ElevationSeries` carries `points`, `totalDistance`, `minElevation`, `maxElevation` and `hasElevation`.
- `profileTotals(series)` answers `distance`, `ascent`, `descent`, `elevationMin`, `elevationMax` and `gradeMax`. `rangeTotals` answers them for a stretch.
- `ResolvedItinerary(itinerary)` holds every projection the data elements read: `geometry`, `legs`, `waypoints`, `characteristics`. `itinerarySegmentRows(series, legs)` and `itineraryWaypointRows` answer the tables' rows.
- The chart's own rules: `profileX`, `profileY`, `profilePolyline`, `profileAreaPath`, `distanceTicks`, `anchoredDomain`, `domainTicks`, `slopeStretches`, `gradeAt`, `detectClimbs`, `buildInfoBands`, `cullCrowdedLabels`.
- `ItineraryResourceEngine(cache, itineraryId)` reads an itinerary by id through an `ItineraryResourceCache`, its `state` a `StateFlow` that reaches `ItineraryResource.Resolved`.

## Read the terrain at a point

The terrain's height, slope and aspect come from the Tile API's elevation tiles. Decode each tile's pixels with your platform's image codec:

```kotlin
import com.mountaya.geo.ElevationEncoding
import com.mountaya.geo.ElevationSource
import com.mountaya.geo.ElevationTile
import com.mountaya.geo.aspectCardinal
import com.mountaya.geo.elevationTilesAt
import com.mountaya.geo.terrainFromElevationTiles

fun terrainAt(here: List<Double>, pixelsOf: (ElevationTile.Address) -> IntArray) {
    val source = ElevationSource(ElevationEncoding.Mapbox, tileSize = 512, zoom = 14)
    val tiles = elevationTilesAt(here, source).map { address -> ElevationTile(address, 512, pixelsOf(address)) }
    val terrain = terrainFromElevationTiles(here, source, tiles)
    println("${terrain?.elevation} m, ${terrain?.slope}°, ${terrain?.aspect?.let(::aspectCardinal)}")
}
```

- `elevationTilesAt(position, source)` answers the tiles the terrain at a point is read off: those holding the four pixel centres around the point and around each of its neighbours a ten-thousandth of a degree north, south, east and west, at the source's deepest zoom, each once, ordered by column then row; none past Web Mercator's latitude. Each `ElevationTile(address, size, pixels)` holds red, green and blue packed as an Android `Bitmap` hands them. `terrainFromElevationTiles` answers a `TerrainReading` (`elevation` in meters, `slope` in degrees from the horizontal, `aspect` the compass bearing the ground falls towards in [0, 360), null on flat ground) or null.
- `decodeElevation(pixel, encoding)` reads one pixel; `slopeAspectFromNeighbours` reads the slope and aspect from a 3 × 3 neighbourhood; `aspectCardinal(degrees)` answers an `AspectCardinal`, whose `code` is the compass word's key.
- The elevation source's encoding and zoom come from the Tile API's layers catalogue (`elevation`). `MapView`'s readout reads the terrain the same way from zoom 13.

## Units and languages

`UnitPreferences` carries the reader's language and units. Every value is written for that reader, never for the device:

```kotlin
import com.mountaya.client.generated.RestSchema
import com.mountaya.geo.TimeLength
import com.mountaya.geo.UnitPreferences
import com.mountaya.geo.formatDateTime
import com.mountaya.geo.formatElevation
import com.mountaya.geo.formatTemperature
import kotlin.time.Instant

fun forAmericanHikers() {
    val units = UnitPreferences("en-US", length = RestSchema.UnitLength.Imperial, temperature = RestSchema.UnitTemperature.Fahrenheit)
    println("${formatElevation(4808.0, units)} ${formatTemperature(-5.0, units)}")
    val start = Instant.parse("2026-07-14T05:30:00Z")
    println(formatDateTime(start, "en-US", "Europe/Paris", timeLength = TimeLength.Short))
}
```

- `UnitPreferences(language, length = Metric | Imperial, pace = PerDistance | PerTime, slope = Percentage | Degrees, temperature = Celsius | Fahrenheit)`, the enums from `RestSchema`. The formatters: `formatDistance`, `formatElevation`, `formatSpeed`, `formatSlope`, `formatTemperature`, `formatDuration`, `formatHumidity`, `formatSnowfall`, `formatAltitudeRange`, `formatPaceClock`, `formatNumber(value, locale, maximumFractionDigits = 3)`.
- Numbers, dates and times are written through the platform's locale services with the locale you pass, never the device's: a number is grouped where the locale's CLDR minimum grouping digits say, on every target, so a Spanish or a Polish 1234 is `1234`.
- `formatDateTime(instant, locale, zone, dateLength, timeLength)` writes the date at a `DateLength`, the time of day at a `TimeLength` (short or medium), or both, in the zone you name, on the locale's own 12- or 24-hour clock; the long date where you name no length. It answers null where the platform knows no zone of that name. On Android it writes through `android.icu`, which `minSdk 24` guarantees.
- `parseTimestamp(text)` (in `com.mountaya.client`) reads a timestamp held as text by the contract's anchor: the instant it names, or null for a date alone, a time with no zone or a day no month holds.
- The elements' words are the contract's tables, in English and French: `WordBundle.elements`, folded with your own by `resolveBundle(bundle, language, overrides)`. `scopeOf(ElementsScope.standard, ElementsScopeStatement(language, locale))` nests a scope; `countedText` and `filledText` fill a counted word. Colours: `ElementTokens.standard`, restyled by `copy { … }` and read with `themeTokenValue(token, ThemeScheme)`.
- `dataLanguageFor("fr-CH")` answers the Data API `Language` for a locale.

## Next steps

- [Turn-by-turn navigation](https://docs.mountaya.com/en/sdks/kotlin/navigation.md): Follow a route with the same rules.
- [Show an elevation profile](https://docs.mountaya.com/en/sdks/kotlin/elevation-profile.md): The same series, drawn in Compose.
