Route - Post Snap To Roads

Applies to: see pricing tiers.

The Snap to Roads API accepts GPS point data, represented as longitude and latitude coordinates, and generates points that aligns with existing roadways on a map. This process, known as "snapping to roads", produces a series of objects that trace a path closely following the road network. The resulting data includes road names and their respective speed limits, pertinent to the traversed segments.

Moreover, the Snap to Roads API offers an interpolation feature, which refines the GPS points to create a smoother route that adheres to the road's geometry. This functionality is especially beneficial for asset tracking and enhancing data visualization in mapping applications.

Important

The GPS points must be within 2.5 kilometer of each other.

For information about routing availability in countries/regions, see Azure Maps routing coverage.

Important

By using this feature, you agree to the preview legal terms. See the Preview Supplemental Terms for additional details.

POST https://atlas.microsoft.com/route/snapToRoads?api-version=2024-07-01-preview

URI Parameters

Name In Required Type Description
api-version
query True

string

Version number of Azure Maps API.

Request Header

Media Types: "application/geo+json"

Name Required Type Description
x-ms-client-id

string

Specifies which account is intended for usage in conjunction with the Microsoft Entra ID security model. It represents a unique ID for the Azure Maps account and can be retrieved from the Azure Maps management plane Account API. To use Microsoft Entra ID security in Azure Maps see the following articles for guidance.

Accept-Language

string

Language in which routing results should be returned.

For more information, see Localization support in Azure Maps.

Request Body

Media Types: "application/geo+json"

Name Required Type Description
features True

InputSnapToRoadsFeaturesItem[]

A set of points to snap to road network. You can have a maximum of 100 points and the two consecutive points must be within 2.5 kilometer of each other. Refer to RFC 7946 for details on the GeoJSON format.

Note: The API will not return a point object in the response for the GPS point that cannot be snapped to a road network.

type True

FeatureTypeEnum

Specifies the GeoJSON type. The only supported object type is FeatureCollection. For more information, see RFC 7946.

includeSpeedLimit

boolean

Specifies whether to include speed limit information for the snapped points in the response. The unit is in kilometers per hour.

Note: Only supported for driving travelMode.

interpolate

boolean

Specifies whether to return additional points between the snapped points to complete the full route path that smoothly follows the road geometry.

The interpolated points will have isInterpolate:true in the response which can be used to identify the snapped points from interpolated points.

travelMode

SnapToRoadsTravelModeEnum

Specifies the routing profile for snapping the points. If unspecified, the default mode is "driving", which optimizes the snapped points for driving routes.

Responses

Name Type Description
200 OK

SnapToRoadsResponse

OK

Media Types: "application/geo+json", "application/json"

Other Status Codes

MapsErrorResponse

An unexpected error occurred.

Media Types: "application/geo+json", "application/json"

Headers

x-ms-error-code: string

Security

AADToken

These are the Microsoft Entra OAuth 2.0 Flows. When paired with Azure role-based access control it can be used to control access to Azure Maps REST APIs. Azure role-based access controls are used to designate access to one or more Azure Maps resource account or sub-resources. Any user, group, or service principal can be granted access via a built-in role or a custom role composed of one or more permissions to Azure Maps REST APIs.

To implement scenarios, we recommend viewing authentication concepts. In summary, this security definition provides a solution for modeling application(s) via objects capable of access control on specific APIs and scopes.

Note

  • This security definition requires the use of the x-ms-client-id header to indicate which Azure Maps resource the application is requesting access to. This can be acquired from the Maps management API.
  • The Authorization URL is specific to the Azure public cloud instance. Sovereign clouds have unique Authorization URLs and Microsoft Entra ID configurations.
  • The Azure role-based access control is configured from the Azure management plane via Azure portal, PowerShell, CLI, Azure SDKs, or REST APIs.
  • Usage of the Azure Maps Web SDK allows for configuration based setup of an application for multiple use cases.
  • For more information on Microsoft identity platform, see Microsoft identity platform overview.

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

Name Description
https://atlas.microsoft.com/.default https://atlas.microsoft.com/.default

subscription-key

This is a shared key that is provisioned when creating an Azure Maps resource through the Azure management plane via Azure portal, PowerShell, CLI, Azure SDKs, or REST APIs.

With this key, any application is authorized to access all REST APIs. In other words, these can currently be treated as master keys to the account which they are issued for.

For publicly exposed applications, our recommendation is to use server-to-server access of Azure Maps REST APIs where this key can be securely stored.

Type: apiKey
In: header

SAS Token

This is a shared access signature token is created from the List SAS operation on the Azure Maps resource through the Azure management plane via Azure portal, PowerShell, CLI, Azure SDKs, or REST APIs.

With this token, any application is authorized to access with Azure role-based access controls and fine-grain control to the expiration, rate, and region(s) of use for the particular token. In other words, the SAS Token can be used to allow applications to control access in a more secured way than the shared key.

For publicly exposed applications, our recommendation is to configure a specific list of allowed origins on the Map account resource to limit rendering abuse and regularly renew the SAS Token.

Type: apiKey
In: header

Examples

Successfully retrieve snap to roads points with additional parameters in the body

Sample request

POST https://atlas.microsoft.com/route/snapToRoads?api-version=2024-07-01-preview

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "coordinates": [
          -122.336729,
          47.590868
        ],
        "type": "Point"
      },
      "properties": {}
    },
    {
      "type": "Feature",
      "geometry": {
        "coordinates": [
          -122.336042,
          47.601604
        ],
        "type": "Point"
      },
      "properties": {}
    }
  ],
  "includeSpeedLimit": true,
  "travelMode": "driving"
}

Sample response

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "coordinates": [
          -122.336769,
          47.590885
        ],
        "type": "Point"
      },
      "properties": {
        "inputIndex": 0,
        "name": "WA-99 N",
        "speedLimitInKilometersPerHour": 80
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "coordinates": [
          -122.336008,
          47.601609
        ],
        "type": "Point"
      },
      "properties": {
        "inputIndex": 1,
        "name": "WA-99 N",
        "speedLimitInKilometersPerHour": 80
      }
    }
  ]
}

Definitions

Name Description
FeaturesItemTypeEnum

Specifies the GeoJSON type. The only supported object type is Feature. For more information, see RFC 7946.

FeatureTypeEnum

Specifies the GeoJSON type. The only supported object type is FeatureCollection. For more information, see RFC 7946.

GeoJsonPoint

A valid GeoJSON Point geometry type. Please refer to RFC 7946 for details.

InputSnapToRoadsFeaturesItem

Specifies the input snap to roads points. GeoJSON feature object and additional properties. Refer to RFC 7946 for details.

MapsErrorDetail

The error detail.

MapsErrorResponse

Common error response for Azure Maps APIs to return error details for failed operations.

MapsInnerError

An object containing more specific information than the current object about the error.

PointGeometry

The origin point passed as a valid GeoJSON Geometry object, from which the range polygon should be calculated. Please refer to RFC 7946 for details.

Note: The API will snap the requested origin point to the nearest road network and will use that for range calculation. It will be returned as a center point in the response.

SnapToRoadFeaturesItem

GeoJSON feature object that contains Geometry object and additional properties of the route.

SnapToRoadsFeatureProperties

Snap to Roads properties.

SnapToRoadsRequest

This object is the request body.

SnapToRoadsResponse

This object is returned from a successful call.

SnapToRoadsTravelModeEnum

Specifies the routing profile for snapping the points. If unspecified, the default mode is "driving", which optimizes the snapped points for driving routes.

FeaturesItemTypeEnum

Specifies the GeoJSON type. The only supported object type is Feature. For more information, see RFC 7946.

Name Type Description
Feature

string

Specifies the GeoJSON Feature object type.

FeatureTypeEnum

Specifies the GeoJSON type. The only supported object type is FeatureCollection. For more information, see RFC 7946.

Name Type Description
FeatureCollection

string

Specifies the GeoJSON FeatureCollection object type.

GeoJsonPoint

A valid GeoJSON Point geometry type. Please refer to RFC 7946 for details.

Name Type Description
coordinates

number[]

A Position is an array of numbers with two or more elements. The first two elements are longitude and latitude, precisely in that order. Altitude/Elevation is an optional third element. Please refer to RFC 7946 for details.

type string:

Point

Specifies the GeoJSON type. Must be one of the nine valid GeoJSON object types - Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, GeometryCollection, Feature and FeatureCollection.

InputSnapToRoadsFeaturesItem

Specifies the input snap to roads points. GeoJSON feature object and additional properties. Refer to RFC 7946 for details.

Name Type Description
geometry GeoJsonPoint:

PointGeometry

A valid GeoJSON Point geometry type. Please refer to RFC 7946 for details.

properties

object

The properties object is required in a valid GeoJSON but it can be empty since the metadata is not used for snapping to road.

type

FeaturesItemTypeEnum

Specifies the GeoJSON type. The only supported object type is Feature. For more information, see RFC 7946.

MapsErrorDetail

The error detail.

Name Type Description
code

string

One of a server-defined set of error codes.

details

MapsErrorDetail[]

An array of details about specific errors that led to this reported error.

innererror

MapsInnerError

An object containing more specific information than the current object about the error.

message

string

A human-readable representation of the error.

target

string

The target of the error.

MapsErrorResponse

Common error response for Azure Maps APIs to return error details for failed operations.

Name Type Description
error

MapsErrorDetail

The error detail.

MapsInnerError

An object containing more specific information than the current object about the error.

Name Type Description
code

string

The error code.

innererror

MapsInnerError

An object containing more specific information than the current object about the error.

PointGeometry

The origin point passed as a valid GeoJSON Geometry object, from which the range polygon should be calculated. Please refer to RFC 7946 for details.

Note: The API will snap the requested origin point to the nearest road network and will use that for range calculation. It will be returned as a center point in the response.

Name Type Description
coordinates

number[]

A Position is an array of numbers with two or more elements. The first two elements are longitude and latitude, precisely in that order. Altitude/Elevation is an optional third element. Please refer to RFC 7946 for details.

type string:

Point

Specifies the geometry type for the GeoJSON Geometry object. For more information, see RFC 7946.

SnapToRoadFeaturesItem

GeoJSON feature object that contains Geometry object and additional properties of the route.

Name Type Description
bbox

number[]

A rectangular area on the earth defined as a bounding box object. The sides of the rectangles are defined by latitude and longitude values. For more information, see RFC 7946, Section 5.

Example: "bbox": [-10.0, -10.0, 10.0, 10.0]

geometry GeoJsonPoint:

PointGeometry

A valid GeoJSON Point geometry type. Please refer to RFC 7946 for details.

properties

SnapToRoadsFeatureProperties

Snap to Roads properties.

type

FeaturesItemTypeEnum

Specifies the GeoJSON type. The only supported object type is Feature. For more information, see RFC 7946.

SnapToRoadsFeatureProperties

Snap to Roads properties.

Name Type Description
inputIndex

integer

Identify the corresponding index in the original list of points for each snapped point. Only the snapped points will return indices and can be used to distinguish them from the interpolated points.

isInterpolated

boolean

Identify whether this is the interpolated point.

name

string

Name of the road the point is snapped to.

speedLimitInKilometersPerHour

number

Speed limit in kilometers per hour.

SnapToRoadsRequest

This object is the request body.

Name Type Default value Description
features

InputSnapToRoadsFeaturesItem[]

A set of points to snap to road network. You can have a maximum of 100 points and the two consecutive points must be within 2.5 kilometer of each other. Refer to RFC 7946 for details on the GeoJSON format.

Note: The API will not return a point object in the response for the GPS point that cannot be snapped to a road network.

includeSpeedLimit

boolean

False

Specifies whether to include speed limit information for the snapped points in the response. The unit is in kilometers per hour.

Note: Only supported for driving travelMode.

interpolate

boolean

False

Specifies whether to return additional points between the snapped points to complete the full route path that smoothly follows the road geometry.

The interpolated points will have isInterpolate:true in the response which can be used to identify the snapped points from interpolated points.

travelMode

SnapToRoadsTravelModeEnum

driving

Specifies the routing profile for snapping the points. If unspecified, the default mode is "driving", which optimizes the snapped points for driving routes.

type

FeatureTypeEnum

Specifies the GeoJSON type. The only supported object type is FeatureCollection. For more information, see RFC 7946.

SnapToRoadsResponse

This object is returned from a successful call.

Name Type Description
features

SnapToRoadFeaturesItem[]

GeoJSON feature object that contains Geometry object and additional properties. Refer to RFC 7946, Section 3.2 for details.

type

FeatureTypeEnum

Specifies the GeoJSON type. The only supported object type is FeatureCollection. For more information, see RFC 7946.

SnapToRoadsTravelModeEnum

Specifies the routing profile for snapping the points. If unspecified, the default mode is "driving", which optimizes the snapped points for driving routes.

Name Type Description
driving

string

The points are snapped to the road suitable for cars.

walking

string

The points are snapped to the pedestrian route including the use of sidewalks.