Skip to content
Documentation menu
docs / api / post-centroid
Routing

POST/centroid

Access and price

AuthAn API key, as Authorization: Bearer snk_… or ?api_key=snk_…. Metered. Needs a full key; a browser (maps) key is refused.
Price1 call per request. Class: standard, or premium for truck and ADR work. Published as unit_rules.default in /pricing.json.
PremiumWhen the body asks for truck routing: "costing": "truck", a top-level adr object or "hazmat": true

What it does

Finds the least-cost meeting point of several locations.

An API key, as Authorization: Bearer snk_… or ?api_key=snk_…. Metered. Price: 1 call per request.

Call it

bash
curl -fsS -X POST "https://api.mapmap.ai/centroid" \
  -H "Authorization: Bearer $MAPMAP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"costing":"auto","locations":[{"lat":51.5074,"lon":-0.1278},{"lat":51.5155,"lon":-0.0922},{"lat":51.4975,"lon":-0.1357}]}'

Request body

application/json

Valhalla centroid request JSON: the same shape as POST /route; locations (at least two), costing, optional costing_options. "Meet in the middle": finds the point in the road graph where paths from every location converge for the least total cost, and returns one path per location to that shared point. Not available from Google, Mapbox, HERE, TomTom or NextBillion

Example: From website/public/docs/api-reference.md:2240

json
{
  "costing": "auto",
  "locations": [
    {
      "lat": 51.5074,
      "lon": -0.1278
    },
    {
      "lat": 51.5155,
      "lon": -0.0922
    },
    {
      "lat": 51.4975,
      "lon": -0.1357
    }
  ]
}

Responses

200A Valhalla route response: trip is the path from locations[0] to the centroid, and each alternates[i] is the path from locations[i+1] to the SAME centroid; every path's last location shares an identical lat/lon, which is the meeting point. costing (e.g. truck) applies identically to every participant's path
FieldTypeRequiredDescription
alternatesobject[]noThe route from each other location to the same point, each { "trip": … }.
tripobjectnoThe route from the first location to the convergence point, as a Valhalla trip (locations, legs, summary).

Example: Recorded from the hosted gateway on 2026-11-05 with a test key: POST /centroid with the request example (three London points, by car); lists trimmed to their first items

json
{
  "alternates": [
    {
      "trip": {
        "language": "en-US",
        "legs": [
          {
            "maneuvers": [
              {
                "begin_shape_index": 0,
                "end_shape_index": 5,
                "instruction": "Drive west on Guildhall.",
                "length": 0.027,
                "street_names": [
                  "Guildhall"
                ],
                "time": 34.895,
                "travel_mode": "drive",
                "travel_type": "car",
                "type": 1,
                "verbal_multi_cue": true,
                "verbal_post_transition_instruction": "Continue for 30 meters.",
                "verbal_pre_transition_instruction": "Drive west on Guildhall. Then Turn left onto Aldermanbury.",
                "verbal_succinct_transition_instruction": "Drive west. Then Turn left onto Aldermanbury."
              },
              {
                "begin_shape_index": 5,
                "end_shape_index": 8,
                "instruction": "Turn left onto Aldermanbury.",
                "length": 0.017,
                "street_names": [
                  "Aldermanbury"
                ],
                "time": 4.314,
                "travel_mode": "drive",
                "travel_type": "car",
                "type": 15,
                "verbal_multi_cue": true,
                "verbal_post_transition_instruction": "Continue for 20 meters.",
                "verbal_pre_transition_instruction": "Turn left onto Aldermanbury. Then Turn right onto Gresham Street.",
                "verbal_succinct_transition_instruction": "Turn left. Then Turn right onto Gresham Street.",
                "verbal_transition_alert_instruction": "Turn left onto Aldermanbury."
              }
            ],
            "shape": "gdggaBpatD?pC@bI?jA?|@?rDzCCLJ`BhBqDtKi@dCs@hEQfAeCbQqGzb@kAxIwJtn@}@bHcBrOgAjHi@pD[~@_JlWgAvD_@~BQrC@fDMvDE|AGtBjBPnD\\lAOl@D|@Hv@J|BXb@Fj@v@t@|AdFt@pM|A~NtBvAw@xB|@z@^n@dCj@`@`DjDfAxAh@l@aAjDSp@o@jCeBn@aA~G_@`B}BzNyB~N_@lCi@jEWhBKpA}@~HyDxVg@`C_CvKMl@mBlJsA~HeAdGs@`EcBxJe@pC]hBkAtGaAvFYbBa@bCkChPcBdKiEpWa@fCc@zBkAdFoAxDgBzEu@nCa@lB_@fBgDbOaFbUcAhEQvFy@lE_FnUe@~BeEdUmJre@kA`HkBxH}@tDoD~IaB|GwAhG}@jEyCnMwCzNsD`XW~Cc@jGkBdWt@`EEpEG|ECfBAlBK|FjE~Fj@t@lFhDdHfCrCl@~OnBxC|C|E^|Cl@",
            "summary": {
              "cost": 681.194,
              "has_ferry": false,
              "has_highway": false,
              "has_toll": false,
              "length": 1.377,
              "max_lat": 51.517696,
              "max_lon": -0.092713,
              "min_lat": 51.515001,
              "min_lon": -0.108057,
              "time": 215.131
            }
          }
        ],
        "locations": [
          {
            "lat": 51.5155,
            "lon": -0.0922,
            "original_index": 1,
            "type": "break"
          },
          {
            "lat": 51.516682,
            "lon": -0.108057,
            "original_index": 0,
            "type": "break"
          }
        ],
        "status": 0,
        "status_message": "Found route between points",
        "summary": {
          "cost": 681.194,
          "has_ferry": false,
          "has_highway": false,
          "has_toll": false,
          "length": 1.377,
          "max_lat": 51.517696,
          "max_lon": -0.092713,
          "min_lat": 51.515001,
          "min_lon": -0.108057,
          "time": 215.131
        },
        "units": "kilometers"
      }
    },
    {
      "trip": {
        "language": "en-US",
        "legs": [
          {
            "maneuvers": [
              {
                "begin_shape_index": 0,
                "begin_street_names": [
                  "Victoria Street",
                  "A302"
                ],
                "end_shape_index": 44,
                "instruction": "Drive east on Victoria Street/A302. Continue on A302.",
                "length": 0.652,
                "street_names": [
                  "A302"
                ],
                "time": 73.696,
                "travel_mode": "drive",
                "travel_type": "car",
                "type": 1,
                "verbal_post_transition_instruction": "Continue on A302 for 700 meters.",
                "verbal_pre_transition_instruction": "Drive east on Victoria Street, A302.",
                "verbal_succinct_transition_instruction": "Drive east."
              },
              {
                "begin_shape_index": 44,
                "end_shape_index": 56,
                "instruction": "Enter the roundabout and take the 2nd exit onto Great George Street/A302.",
                "length": 0.115,
                "roundabout_exit_count": 2,
                "time": 15.342,
                "travel_mode": "drive",
                "travel_type": "car",
                "type": 26,
                "verbal_pre_transition_instruction": "Enter the roundabout and take the 2nd exit onto Great George Street, A302.",
                "verbal_succinct_transition_instruction": "Enter the roundabout and take the 2nd exit.",
                "verbal_transition_alert_instruction": "Enter the roundabout and take the 2nd exit onto Great George Street."
              }
            ],
            "shape": "m`dfaB`|gGq@oKSiCUuCqBsReAyKmE{W}AeJUyAwAgHmB}Im@{BcVi|@qEmPgBmH",
            "summary": {
              "cost": 640.256,
              "has_ferry": false,
              "has_highway": false,
              "has_toll": false,
              "length": 3.549,
              "max_lat": 51.516682,
              "max_lon": -0.108057,
              "min_lat": 51.497495,
              "min_lon": -0.135632,
              "time": 416.277
            }
          }
        ],
        "locations": [
          {
            "lat": 51.4975,
            "lon": -0.1357,
            "original_index": 2,
            "type": "break"
          },
          {
            "lat": 51.516682,
            "lon": -0.108057,
            "original_index": 0,
            "type": "break"
          }
        ],
        "status": 0,
        "status_message": "Found route between points",
        "summary": {
          "cost": 640.256,
          "has_ferry": false,
          "has_highway": false,
          "has_toll": false,
          "length": 3.549,
          "max_lat": 51.516682,
          "max_lon": -0.108057,
          "min_lat": 51.497495,
          "min_lon": -0.135632,
          "time": 416.277
        },
        "units": "kilometers"
      }
    }
  ],
  "trip": {
    "language": "en-US",
    "legs": [
      {
        "maneuvers": [
          {
            "begin_shape_index": 0,
            "end_shape_index": 7,
            "instruction": "Drive northeast on Charing Cross.",
            "length": 0.02,
            "roundabout_exit_count": 1,
            "street_names": [
              "Charing Cross"
            ],
            "time": 2.469,
            "travel_mode": "drive",
            "travel_type": "car",
            "type": 2,
            "verbal_post_transition_instruction": "Continue for 20 meters.",
            "verbal_pre_transition_instruction": "Drive northeast on Charing Cross.",
            "verbal_succinct_transition_instruction": "Drive northeast."
          },
          {
            "begin_shape_index": 7,
            "begin_street_names": [
              "Trafalgar Square",
              "A4"
            ],
            "end_shape_index": 21,
            "instruction": "Exit the roundabout onto Trafalgar Square/A4. Continue on Trafalgar Square.",
            "length": 0.126,
            "street_names": [
              "Trafalgar Square"
            ],
            "time": 14.357,
            "travel_mode": "drive",
            "travel_type": "car",
            "type": 27,
            "verbal_post_transition_instruction": "Continue on Trafalgar Square for 100 meters.",
            "verbal_pre_transition_instruction": "Exit the roundabout onto Trafalgar Square, A4.",
            "verbal_succinct_transition_instruction": "Exit the roundabout."
          }
        ],
        "shape": "kpwfaBx|xFQU]i@]o@_@iA]yAWuBSsB}CoMs@eDwBiHu@{A}@cA}@_@eAMkBB{AJqQfDqGvBiAXiAXoAJu@y@k@e@Y}@IgCF}HAgEe@cIEo[IuCUkIEaFCyTIaBMyBm@sA{@qB_A{BkE_Km@qA{KgYePs`@q@eB_CoG}Pgc@qFePaByEkHcSuLy_@mDyLsBsGaDqK{@}CoFmRiAcEwJi^aJw\\kD{Lk@{BeAaEgBqGg@sBaAcD_@sABmIaAeCu@{A}AeCe@q@u@u@_@Sy@g@]QwAIcDJmAPyALaMa@wCe@uDo@gDaAi@QgHqCaE{Ck@a@kIwHcE{EoBoCyAsC{EqJgF_No@gCe@oBc@qB}AiI_BiJ_@cDYuC]aDq@wIKuBW_FSqFKqGCmFBcEHaDDeBJoEp@iMRoA\\eClGga@jAyE`@gBr@iDl@eCl@qBvAwDx@gBpAoBzD{DoAuIc@uBWiB]aE_@aEMuD}@}JaAwFw@sBuA{CuEaH_DgD}@iAsAeCiC{I}CyMgDyGG[kBwBOw@KgAPaEIa@eCuNu@oEeA_AIS[iC?a@^}ACc@}@aKU{CI}@_@aFY{DOgCGu@Eo@k@kGUaCI_AiAs@mDs`@iAgKm@gFRuEo@qDU_Bm@cEEi@UiBSoBw@{IqDx@{AXuBp@iCdAwDzAgE~@oD`@gCVsK]iD]}JeD_GqB_TgIaA{DiBwBc@e@_G}Ha`@{l@eCiCkCmBcDmBo@M",
        "summary": {
          "cost": 394.166,
          "has_ferry": false,
          "has_highway": false,
          "has_toll": false,
          "length": 2.01,
          "max_lat": 51.516682,
          "max_lon": -0.108057,
          "min_lat": 51.507478,
          "min_lon": -0.127964,
          "time": 238.53
        }
      }
    ],
    "locations": [
      {
        "lat": 51.5074,
        "lon": -0.1278,
        "original_index": 0,
        "side_of_street": "right",
        "type": "break"
      },
      {
        "lat": 51.516682,
        "lon": -0.108057,
        "original_index": 0,
        "type": "break"
      }
    ],
    "status": 0,
    "status_message": "Found route between points",
    "summary": {
      "cost": 394.166,
      "has_ferry": false,
      "has_highway": false,
      "has_toll": false,
      "length": 2.01,
      "max_lat": 51.516682,
      "max_lon": -0.108057,
      "min_lat": 51.507478,
      "min_lon": -0.127964,
      "time": 238.53
    },
    "units": "kilometers"
  }
}
400Invalid request, or fewer than two locations (Valhalla error_code 120)

application/problem+json · Problem

401Missing or invalid API key. Also: No key, or a missing, malformed, unknown, revoked or expired one (unauthorized); the body carries signup, docs and a one-call hint for a free key

application/problem+json · Problem

402Beyond the included volume with no way to pay this call: an x402 body naming how to pay (provisional key past its allowance, prepaid balance below the price, or a rejected X-PAYMENT). Not problem+json

application/json · X402PaymentRequired

403The key may not call this: a browser key outside its scope (scope-insufficient), a request from an origin the key does not allow (origin-not-allowed), or an account restriction (forbidden)

application/problem+json · Problem

413The request declares a body larger than 1048576 bytes (plain text, not problem+json)

text/plain

429Quota or rate limit exceeded. Also: Per-key rate limit (rate-limited, with Retry-After), or monthly quota exhausted with no payment path (quota-exceeded)

application/problem+json · Problem

501SN_ROUTING_ENGINE=graphhopper: GraphHopper has no centroid service

application/problem+json · Problem

502Upstream routing engine failed

application/problem+json · Problem

504The request did not finish within the gateway's request deadline (request-timeout)

application/problem+json · Problem

Error bodies follow the shared problem model documented on API conventions.

Also under Routing

Generated from https://api.mapmap.ai/openapi.json on 2026-11-12 · operationId post_centroid