Get started
Dart and Flutter SDK

Geo and navigation

Geo without a map

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

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.

Build an elevation series

The series every profile draws is a rule too:

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.

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:

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 shows it.

Units and languages

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

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'));

Next steps

Last updated