Skip to content
GuidesBlogPlaygroundDashboard

Match GPS coordinates to the road network

client.MapMatch.Match(ctx, body) (*MapMatchResult, error)
POST/api/v1/map-match

Match GPS coordinates to the road network

ParametersExpand Collapse
body MapMatchMatchParams
MapMatchRequest param.Field[MapMatchRequest]

GPS trace to snap to the road network. Provide an array of coordinate objects representing the GPS points. Maximum 50 points per request.

ReturnsExpand Collapse
type MapMatchResult struct{…}

Map matching result as a GeoJSON FeatureCollection. Each Feature is a snapped tracepoint. The top-level matchings array contains the matched sub-routes connecting consecutive tracepoints.

Features []MapMatchResultFeature

Snapped tracepoint Features in input order

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 MapMatchResultFeaturesProperties
DistanceM float64optional

Distance from the original GPS point to the snapped point in meters

EdgeID int64optional

Road edge ID the point was snapped to

MatchingsIndex int64optional

Index into the matchings array indicating which matching sub-route this point belongs to

Name stringoptional

Road name at the snapped point

Original []float64optional

Original GPS coordinate as [lng, lat]

WaypointIndex int64optional

Index of this tracepoint in the original coordinates array

Type MapMatchResultFeaturesType
Matchings []map[string, unknown]

Matched sub-routes. Each matching connects a contiguous sequence of tracepoints that could be matched to roads.

Type MapMatchResultType

Match GPS coordinates to the road network

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"),
  )
  mapMatchResult, err := client.MapMatch.Match(context.TODO(), githubcomplazafyiplazago.MapMatchMatchParams{
    MapMatchRequest: githubcomplazafyiplazago.MapMatchRequestParam{
      Coordinates: githubcomplazafyiplazago.F([]githubcomplazafyiplazago.MapMatchRequestCoordinateParam{githubcomplazafyiplazago.MapMatchRequestCoordinateParam{
        Lat: githubcomplazafyiplazago.F(48.856600),
        Lng: githubcomplazafyiplazago.F(2.352200),
      }, githubcomplazafyiplazago.MapMatchRequestCoordinateParam{
        Lat: githubcomplazafyiplazago.F(48.857000),
        Lng: githubcomplazafyiplazago.F(2.353000),
      }, githubcomplazafyiplazago.MapMatchRequestCoordinateParam{
        Lat: githubcomplazafyiplazago.F(48.857500),
        Lng: githubcomplazafyiplazago.F(2.354000),
      }}),
    },
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", mapMatchResult.Features)
}
{
  "features": [
    {
      "geometry": {
        "coordinates": [
          2.3522,
          48.8566
        ],
        "type": "Point"
      },
      "properties": {
        "distance_m": 0,
        "edge_id": 0,
        "matchings_index": 0,
        "name": "name",
        "original": [
          0,
          0
        ],
        "waypoint_index": 0
      },
      "type": "Feature"
    }
  ],
  "matchings": [
    {
      "foo": "bar"
    }
  ],
  "type": "FeatureCollection"
}
Returns Examples
{
  "features": [
    {
      "geometry": {
        "coordinates": [
          2.3522,
          48.8566
        ],
        "type": "Point"
      },
      "properties": {
        "distance_m": 0,
        "edge_id": 0,
        "matchings_index": 0,
        "name": "name",
        "original": [
          0,
          0
        ],
        "waypoint_index": 0
      },
      "type": "Feature"
    }
  ],
  "matchings": [
    {
      "foo": "bar"
    }
  ],
  "type": "FeatureCollection"
}