Skip to content
GuidesBlogPlaygroundDashboard

Calculate a route between two points

client.Routing.Route(ctx, params) (*RouteResult, error)
POST/api/v1/route

Calculate a route between two points

ParametersExpand Collapse
params RoutingRouteParams
RouteRequest param.Field[RouteRequest]

Body param: Request body for route calculation. Origin and destination are lat/lng coordinate objects. Supports optional waypoints, alternative routes, turn-by-turn steps, and EV routing parameters.

Format param.Field[string]optional

Query param: Response format for alternatives: json (default), geojson, csv, ndjson

ReturnsExpand Collapse
type RouteResult struct{…}

GeoJSON Feature representing a calculated route. The geometry is a LineString or MultiLineString of the route path. When alternatives > 0, the response is a FeatureCollection containing multiple route Features.

GeoJSON Geometry object per RFC 7946. Coordinates use [longitude, latitude] order. 3D coordinates [lng, lat, elevation] are used for elevation endpoints.

Coordinates GeoJsonGeometryCoordinatesUnion

Coordinates array. Nesting depth varies by geometry type: Point = [lng, lat], LineString = [[lng, lat], ...], Polygon = [[[lng, lat], ...], ...], etc.

One of the following:
type GeoJsonGeometryCoordinatesPoint []float64

[longitude, latitude] or [longitude, latitude, elevation]

type GeoJsonGeometryCoordinatesLineStringOrMultiPoint [][]float64

Array of [lng, lat] positions

type GeoJsonGeometryCoordinatesPolygonOrMultiLineString [][][]float64

Array of linear rings / line strings

type GeoJsonGeometryCoordinatesMultiPolygon [][][][]float64

Array of polygons

Type GeoJsonGeometryType

Geometry type

One of the following:
const GeoJsonGeometryTypePoint GeoJsonGeometryType = "Point"
const GeoJsonGeometryTypeLineString GeoJsonGeometryType = "LineString"
const GeoJsonGeometryTypePolygon GeoJsonGeometryType = "Polygon"
const GeoJsonGeometryTypeMultiPoint GeoJsonGeometryType = "MultiPoint"
const GeoJsonGeometryTypeMultiLineString GeoJsonGeometryType = "MultiLineString"
const GeoJsonGeometryTypeMultiPolygon GeoJsonGeometryType = "MultiPolygon"
Properties RouteResultProperties

Route metadata

DistanceM float64

Total route distance in meters

DurationS float64

Estimated travel duration in seconds

Annotations map[string, unknown]optional

Per-edge annotations (present when annotations: true in request)

ChargeProfile [][]float64optional

Battery charge level at route waypoints as [distance_fraction, charge_pct] pairs (EV routes only)

ChargingStops []map[string, unknown]optional

Recommended charging stops along the route (EV routes only)

Edges []map[string, unknown]optional

Edge-level route details (present when annotations: true)

EnergyUsedWh float64optional

Total energy consumed in watt-hours (EV routes only)

Type RouteResultType

Calculate a route between two points

package main

import (
  "context"
  "fmt"

  "github.com/plazafyi/plaza-go"
  "github.com/plazafyi/plaza-go/option"
)

func main() {
  client := githubcomplazafyiplazago.NewClient(
    option.WithAPIKey("My API Key"),
  )
  routeResult, err := client.Routing.Route(context.TODO(), githubcomplazafyiplazago.RoutingRouteParams{
    RouteRequest: githubcomplazafyiplazago.RouteRequestParam{
      Destination: githubcomplazafyiplazago.F(githubcomplazafyiplazago.RouteRequestDestinationParam{
        Lat: githubcomplazafyiplazago.F(48.858400),
        Lng: githubcomplazafyiplazago.F(2.294500),
      }),
      Origin: githubcomplazafyiplazago.F(githubcomplazafyiplazago.RouteRequestOriginParam{
        Lat: githubcomplazafyiplazago.F(48.856600),
        Lng: githubcomplazafyiplazago.F(2.352200),
      }),
    },
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", routeResult.Geometry)
}
{
  "geometry": {
    "coordinates": [
      2.3522,
      48.8566
    ],
    "type": "Point"
  },
  "properties": {
    "distance_m": 4523.7,
    "duration_s": 847.2,
    "annotations": {
      "foo": "bar"
    },
    "charge_profile": [
      [
        0
      ]
    ],
    "charging_stops": [
      {
        "foo": "bar"
      }
    ],
    "edges": [
      {
        "foo": "bar"
      }
    ],
    "energy_used_wh": 0
  },
  "type": "Feature"
}
Returns Examples
{
  "geometry": {
    "coordinates": [
      2.3522,
      48.8566
    ],
    "type": "Point"
  },
  "properties": {
    "distance_m": 4523.7,
    "duration_s": 847.2,
    "annotations": {
      "foo": "bar"
    },
    "charge_profile": [
      [
        0
      ]
    ],
    "charging_stops": [
      {
        "foo": "bar"
      }
    ],
    "edges": [
      {
        "foo": "bar"
      }
    ],
    "energy_used_wh": 0
  },
  "type": "Feature"
}