# Geo without a map

> Canonical URL: https://docs.mountaya.com/en/sdks/dart/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 in pure Dart.

`mountaya_geo` holds Mountaya's rules as plain Dart functions. It calls no network and draws nothing, so a server, a test or a widget of your own reads the same numbers the elements show.

## Measure and format distances

```dart
import 'package:mountaya_geo/mountaya_geo.dart';

// A position is [longitude, latitude], as the APIs write it.
const chamonix = [6.8712, 45.9231];
const argentiere = [6.9271, 45.9822];
// The crow's distance, and a route's length along its line.
final direct = haversineMeters(chamonix, argentiere);
final along = routeLengthMeters([chamonix, argentiere]);

const units = UnitPreferences(language: 'fr-FR');
print('${formatDistance(along, units)}, ${formatDistance(direct, units)} as the crow flies');
```

Every rule answers the same numbers and words in every Mountaya SDK, under the same name.

- Geodesy: `haversineMeters(a, b)`, `routeLengthMeters(line)`, `cumulativeMeters(line)`, `positionAtMeters(line, meters)`, `bearingDegrees(from, to)`, `distanceToSegment(point, start, end)`, `metersToRoute(point, lines)`, `boundsOf(geometries)`, `wrapLongitude`. Radius: `earthRadiusMeters`.
- A rule handed a position that names no place answers rather than throws: a distance is `NaN`, a printed position (`formatLngLat`) `null`.
- Formatting: `formatDistance`, `formatElevation`, `formatAltitudeRange`, `formatDuration`, `formatSpeed`, `formatSlope`, `formatTemperature`, `formatSnowfall`, `formatHumidity`, `formatNumber`, `formatPaceClock`, `formatLngLat`. Numbers are written through `package:intl` in the locale you name, never `Intl.defaultLocale`, grouped as CLDR groups them (1531 is `1,531` in English and `1531` in Polish and Spanish).
- Conversions: `convertLength`, `convertSpeed`, `convertSlope`, `convertTemperature`, `convertDuration`, `convertAngle`.
- Every value Geo derives compares structurally, `NaN` equal to `NaN` and `0` apart from `-0`.
- The geo layer depends on `mountaya_client` for its types (Dart has no type-only dependency) and never calls it.

## Build an elevation series

The series every profile draws is a rule too:

```dart
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_geo/mountaya_geo.dart';

// The third coordinate of each position is its elevation in meters.
// Chamonix to Argentière.
final geometry = GeoJsonLineString([
  [6.8712, 45.9231, 1035],
  [6.9271, 45.9822, 1252],
]);
final series = buildElevationSeries(geometry);
final totals = profileTotals(series);

const units = UnitPreferences(language: 'en');
print(
  '${formatDistance(totals.distance, units)}, '
  '${formatElevation(totals.ascent, units)} up, '
  '${formatElevation(totals.descent, units)} down',
);
```

For a whole itinerary, `ResolvedItinerary(itinerary)` gives the geometry and the legs, and `itinerarySegmentRows` the rows a segment table states.

- `buildElevationSeries(geometry, {maxPoints = maxProfilePoints})` answers an `ElevationSeries`: `points` (each `distance`, `elevation`, `lngLat`, `index`), `totalDistance`, `minElevation`, `maxElevation`, `hasElevation`. A vertex with no third coordinate advances the distance and draws no point.
- `profileTotals(series)` answers `distance`, `ascent`, `descent`, `elevationMin`, `elevationMax`, `gradeMax`, with noise under `elevationNoiseThresholdMeters` ignored; `rangeTotals(series, from, to)` the same over a stretch.
- `ResolvedItinerary(itineraryWithDetails)` projects an answer of `getItinerary` into `geometry`, `legs` (`ItineraryLeg`), `waypoints` (`ItineraryPlace`) and `characteristics`. `itinerarySegmentRows(series, legs)` and `itineraryWaypointRows(series, geometry, places)` are the tables' rows; `profileCharacteristics(segments, waypoints:)` and `committedPace(segments)` read the wire's own values.
- `detectClimbs(points)` finds the climbs and `climbCategoryFor(lengthMeters, avgGradePercent)` rates them; `slopeStretches(points)` colours the curve by gradient.
- `ItineraryResourceCache` and `ItineraryResourceEngine` (Geo's too) read an itinerary through your client for the elements; see [elevation profile](https://docs.mountaya.com/en/sdks/dart/elevation-profile.md#draw).

## Read the terrain at a point

`terrainFromElevationTiles` reads the altitude, slope and aspect at a point off elevation tiles you hold. `elevationTilesAt` names the tiles it needs:

```dart
import 'dart:typed_data';

import 'package:mountaya_geo/mountaya_geo.dart';

// Each tile's pixels, decoded to RGBA by your image codec.
Future<TerrainReading?> terrainAt(
  List<double> position,
  ElevationSource source,
  Future<Uint8List> Function(ElevationTile tile) readTile,
) async {
  final tiles = {
    for (final tile in elevationTilesAt(position, source))
      tile: await readTile(tile),
  };
  return terrainFromElevationTiles(position, source, tiles);
}

// The aspect's direction, from a reading's degrees.
String? facing(TerrainReading reading) => switch (reading.aspect) {
  final degrees? => aspectCardinal(degrees)?.id,
  null => null,
};
```

On a map, the readout does this for you. [Read a point](https://docs.mountaya.com/en/sdks/dart/map.md#readout) shows it.

- `ElevationSource(tileSize:, zoom:, encoding:)`: the layers catalogue's `elevation` names the source's TileJSON (`elevation.url`), whose `encoding` (`ElevationEncoding.mapbox` or `terrarium`), `maxzoom` and tile template it states, and `elevation.tile_size`. The Tile API serves the tiles to a credential carrying `tiles`.
- A tile's pixels are its RGBA bytes, row by row from the north and each row from the west, four bytes a pixel, `tileSize` pixels a side, as a platform's image codec writes a decoded image (in Flutter, `ui.instantiateImageCodec` then `toByteData(format: ImageByteFormat.rawRgba)`). The alpha channel is read by no encoding.
- The terrain is read at the point and `elevationNeighbourDegrees` (one ten-thousandth of a degree) to its north, south, east and west, each the bilinear mix of the four pixel centres around it; the slope and aspect are `slopeAspectFromNeighbours`. It answers `null` where a tile a place needs is not at hand or holds too few bytes, past Web Mercator's latitude, or where the encoding reads no height.
- `decodeElevation(pixel, encoding:)` reads one pixel. `aspectCardinal(degrees)` answers the `AspectCardinal` (eight directions), `classifySteepness(degrees)` the `SteepnessClass`, `formatSlope` writes it.
- Without tiles: `MapEngine.elevationAt(position)` and the Data API's `mountaya.data.terrainSamples` answer the ground's elevation, slope and aspect over the network.

## Units and languages

A value is written for its reader, in their language and units, never the device's:

```dart
import 'package:mountaya_client/rest_schema.dart' as rest_schema;
import 'package:mountaya_geo/mountaya_geo.dart';

final imperial = UnitPreferences(
  language: 'en-US',
  length: rest_schema.UnitLength.imperial,
  temperature: rest_schema.UnitTemperature.fahrenheit,
);
print(formatDistance(12500, imperial));
print(formatElevation(1252, imperial));

// The label language a map and the elements speak, from a reader's tag.
print(labelLanguage('fr-CH'));
```

- `UnitPreferences({required String language, UnitLength length = metric, UnitPace pace = perTime, UnitSlope slope = degrees, UnitTemperature temperature = celsius})`, each preference the wire's own vocabulary from `rest_schema` (`UnitLength.imperial`, `UnitPace.perDistance`, `UnitSlope.percentage`), so a misspelt one does not compile. `copyWith` changes one.
- `labelLanguage(tag)` reads the label `Language` off a tag such as `fr-CH` (English where the tiles carry none of it); `dataLanguageFor(tag)` the Data API's. `labelLanguages` and `languageEndonyms` list them.
- `formatDateTime(instant, locale, timeZone, {dateLength, timeLength})` writes an instant in the IANA zone you name, in the locale's style and on its own clock, Gregorian whatever calendar the locale keeps; `null` for a zone name the tz data holds none of. Load its data off the UI isolate once with `prepareFormatDateTime()`.
- The elements' words in English and French are `WordBundle.elements`; `resolveBundle(bundle, language:, overrides:)` folds your own over them. Colours are `ElementTokens.standard` (`copyWith` restyles), glyphs `GlyphSet.marker` and `GlyphSet.control`.

## Next steps

- [Turn-by-turn navigation](https://docs.mountaya.com/en/sdks/dart/navigation.md): Follow a route with Geo's navigation engine.
- [Testing](https://docs.mountaya.com/en/sdks/dart/testing.md): Scripted engines and a fake clock.
