# Map Match ## 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 ### Parameters - `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. ### Returns - `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 - `Geometry GeoJsonGeometry` 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. - `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 - `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 float64` Distance from the original GPS point to the snapped point in meters - `EdgeID int64` Road edge ID the point was snapped to - `MatchingsIndex int64` Index into the `matchings` array indicating which matching sub-route this point belongs to - `Name string` Road name at the snapped point - `Original []float64` Original GPS coordinate as [lng, lat] - `WaypointIndex int64` Index of this tracepoint in the original `coordinates` array - `Type MapMatchResultFeaturesType` - `const MapMatchResultFeaturesTypeFeature MapMatchResultFeaturesType = "Feature"` - `Matchings []map[string, unknown]` Matched sub-routes. Each matching connects a contiguous sequence of tracepoints that could be matched to roads. - `Type MapMatchResultType` - `const MapMatchResultTypeFeatureCollection MapMatchResultType = "FeatureCollection"` ### Example ```go 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) } ``` #### Response ```json { "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" } ``` ## Domain Types ### Map Match Request - `type MapMatchRequest struct{…}` GPS trace to snap to the road network. Provide an array of coordinate objects representing the GPS points. Maximum 50 points per request. - `Coordinates []MapMatchRequestCoordinate` GPS coordinates to match, in order of travel (max 50 points) - `Lat float64` Latitude in decimal degrees (-90 to 90) - `Lng float64` Longitude in decimal degrees (-180 to 180) - `Radiuses []float64` Search radius per coordinate in meters. Must have the same length as `coordinates` or be omitted entirely. Default: 50m per point. ### Map Match Result - `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 - `Geometry GeoJsonGeometry` 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. - `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 - `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 float64` Distance from the original GPS point to the snapped point in meters - `EdgeID int64` Road edge ID the point was snapped to - `MatchingsIndex int64` Index into the `matchings` array indicating which matching sub-route this point belongs to - `Name string` Road name at the snapped point - `Original []float64` Original GPS coordinate as [lng, lat] - `WaypointIndex int64` Index of this tracepoint in the original `coordinates` array - `Type MapMatchResultFeaturesType` - `const MapMatchResultFeaturesTypeFeature MapMatchResultFeaturesType = "Feature"` - `Matchings []map[string, unknown]` Matched sub-routes. Each matching connects a contiguous sequence of tracepoints that could be matched to roads. - `Type MapMatchResultType` - `const MapMatchResultTypeFeatureCollection MapMatchResultType = "FeatureCollection"`