Get started
Data API

Routing

Routing

Four queries route on the trail network: directions between waypoints, suggestions shaped to a distance, isochrones for the ground in reach, and matrix for travel times between places.

Set up

Every sample on this page reuses this setup. It mints a session token with your secret key, so run it on your server.

export MOUNTAYA_PUBLISHABLE_KEY="pk_your_publishable_key"
export MOUNTAYA_SESSION_TOKEN=$(curl -s -X POST https://api.mountaya.com/v1/sessions \
  -H "X-API-Key: $MOUNTAYA_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"publishable_key\": \"$MOUNTAYA_PUBLISHABLE_KEY\"}" | jq -r .data.token)

A session token lasts five minutes, so mint a new one when it expires. Authentication covers tokens in a browser.

Directions

Route a hike from Chamonix to Argentière. Coordinates are [longitude, latitude].

curl https://data.mountaya.com/graphql \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query Directions($input: DirectionsInput!) { directions(input: $input) { routes { distance duration summary avoidance } } }",
    "variables": {
      "input": {
        "activity": "HIKING_AND_TRAIL",
        "waypoints": [[6.8712, 45.9231], [6.9271, 45.9822]],
        "avoid": ["TOLLWAY", "RESTRICTED_ACCESS"]
      }
    }
  }'
Response
{
  "data": {
    "directions": {
      "routes": [
        {
          "distance": 9005.14542243658,
          "duration": 9631.009017156648,
          "summary": "9.0 km, ~2h40m, +277m / -56m elevation, 67% path, 12% track, 8% road.",
          "avoidance": "NOT_NEEDED"
        }
      ]
    }
  }
}

distance is in meters and duration in seconds. The duration follows the terrain: a climb is slower than a descent. Select geometry for the route as a GeoJSON line, and elevation for its ascent and descent.

Hazards and avoidance

Some ways carry a toll or an access restriction, such as private or permit-only land. directions may cross one, so read analysis.advisories before you show the route. Pass avoid to route around them, then read avoidance.

avoidanceMeaning
NOT_REQUESTEDYou sent no avoid list.
NOT_NEEDEDThe route crossed none of the hazards you named.
APPLIEDThe route was rerouted around them. Check advisories for any other hazard.
NO_ROUTENo route avoids them, so the original route comes back.

Suggestions

Ask for routes shaped to a distance and an ascent. This one looks for a longer way to Argentière: about 12 km with 600 m of climbing.

curl https://data.mountaya.com/graphql \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query Suggestions($input: SuggestionsInput!) { suggestions(input: $input) { routes { seed distance duration summary } } }",
    "variables": {
      "input": {
        "activity": "HIKING_AND_TRAIL",
        "start": [6.8712, 45.9231],
        "end": [6.9271, 45.9822],
        "distance": 12000,
        "ascent": 600,
        "candidates": 3
      }
    }
  }'
Response
{
  "data": {
    "suggestions": {
      "routes": [
        {
          "seed": 1647174438,
          "distance": 11462.699479476818,
          "duration": 13465.759617296519,
          "summary": "11.5 km, ~3h44m, +599m / -379m elevation, 79% path, 8% track, 5% road."
        },
        {
          "seed": 967324718,
          "distance": 13064.673161567045,
          "duration": 15522.708185158344,
          "summary": "13.1 km, ~4h18m, +653m / -433m elevation, 81% path, 7% track, 4% road."
        },
        {
          "seed": 416961995,
          "distance": 12933.929808013665,
          "duration": 15299.575502044987,
          "summary": "12.9 km, ~4h15m, +668m / -448m elevation, 82% path, 5% street, 5% track."
        }
      ]
    }
  }
}

Candidates come back closest to your targets first. Send a seed back in seeds.include to get the same route again.

Leave out end for a loop back to start. A suggestion never crosses a tollway or an access-restricted way.

Isochrones

Map the ground you can reach from a point within a time or a distance. This asks for 30 and 60 minutes on foot from Chamonix.

curl https://data.mountaya.com/graphql \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query Isochrones($input: IsochronesInput!) { isochrones(input: $input) { isochrones { value area reachFactor } } }",
    "variables": {
      "input": {
        "activity": "HIKING_AND_TRAIL",
        "locations": [[6.8712, 45.9231]],
        "range": [1800, 3600],
        "rangeType": "TIME"
      }
    }
  }'
Response
{
  "data": {
    "isochrones": {
      "isochrones": [
        {
          "value": 1800,
          "area": 3.63273032e+06,
          "reachFactor": 0.2891
        },
        {
          "value": 3600,
          "area": 9.12239342e+06,
          "reachFactor": 0.1815
        }
      ]
    }
  }
}

Each range value returns one polygon: select geometry to draw it. area is in square meters. A low reachFactor means the trails are hemmed in, as in a valley.

Matrix

Compare travel times and distances between many places at once. This grid links Chamonix, Argentière, and Les Houches.

curl https://data.mountaya.com/graphql \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY" \
  -H "X-Session-Token: $MOUNTAYA_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "query Matrix($input: MatrixInput!) { matrix(input: $input) { durations distances } }",
    "variables": {
      "input": {
        "activity": "HIKING_AND_TRAIL",
        "locations": [[6.8712, 45.9231], [6.9271, 45.9822], [6.7991, 45.8915]],
        "metrics": ["DURATION", "DISTANCE"]
      }
    }
  }'
Response
{
  "data": {
    "matrix": {
      "durations": [
        [0, 6481.25, 5564.66],
        [6481.25, 0, 11977.68],
        [5564.66, 11977.68, 0]
      ],
      "distances": [
        [0, 9001.81, 7728.75],
        [9001.81, 0, 16635.78],
        [7728.75, 16635.78, 0]
      ]
    }
  }
}

Row i, column j is the trip from location i to location j. A null cell has no route.

Activities

Every query takes an activity, which picks the ways it routes on and its default pace.

ActivityAPI valueWire formDirections
Hiking and trail runningHIKING_AND_TRAILhiking-and-trailYes
Professional trailPROFESSIONAL_TRAILprofessional-trailYes, off-network
RunningRUNNINGrunningYes
Road cyclingROAD_CYCLINGroad-cyclingYes
Gravel bikingGRAVEL_BIKEgravel-bikeUnavailable
Mountain bikingMOUNTAIN_BIKEmountain-bikeUnavailable
Backcountry skiingBACKCOUNTRY_SKIINGbackcountry-skiingFreehand line only
Ski touringSKI_TOURINGski-touringYes, off-network
Cross-country skiingCROSS_COUNTRY_SKIINGcross-country-skiingYes
Snowshoe walkingSNOWSHOE_WALKINGsnowshoe-walkingYes

Each routed activity uses a profile tuned to its terrain and movement style. Most activities support turn-by-turn routing, road cycling among them. Backcountry skiing is freehand-line only: no query routes it. Gravel biking and mountain biking are unavailable: the activity catalog does not list them, and every query refuses them, analyzeGeometry included. The GraphQL ActivitySlug enum uses the uppercase value; the Map Studio and Tile APIs use the kebab-case wire form, the same value lowercased with each underscore turned into a hyphen.

Next steps

Last updated