Route - Post Snap To Roads Batch

SnapToRoads Batch API

Applies to: see pricing tiers.

The Snap To Roads Batch API sends batches of up to 100 queries as a single call to the Snap To Roads API.

Important

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

Submit Synchronous Batch Request

The Synchronous API is recommended for lightweight batch requests. When the service receives a request, it will respond as soon as the batch items are calculated and there will be no possibility to retrieve the results later. The Synchronous API will return a timeout error (a 408 response) if the request takes longer than 60 seconds. The number of batch items is limited to 100 for this API.

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

POST Body for Batch Request

To send the snap to roads queries you will use a POST request where the request body will contain the batchItems array in json format and the Content-Type header will be set to application/json. Here's a sample request body containing 2 snap to roads queries:

{
  "batchItems": [
    {
      "type": "FeatureCollection",
      "features": [
        {
          "type": "Feature",
          "geometry": {
            "coordinates": [
              -122.122353,
              47.672662
            ],
            "type": "Point"
          },
          "properties": {
                         
          }
        },
        {
          "type": "Feature",
          "geometry": {
            "coordinates": [
              -122.132452,
              47.644234
            ],
            "type": "Point"
          },
          "properties": {
                             
          }
        }
      ],
      "interpolate": true,
      "includeSpeedLimit": true,
      "travelMode": "driving"
    },
    {
      "type": "FeatureCollection",
      "features": [
        {
          "type": "Feature",
          "geometry": {
            "coordinates": [
              -122.33669,
              47.590849
            ],
            "type": "Point"
          },
          "properties": {
            "pointIndex": 0
          }
        },
        {
          "type": "Feature",
          "geometry": {
            "coordinates": [
              122.34509,
              47.610524
            ],
            "type": "Point"
          },
          "properties": {
            "pointIndex": 1
          }
        }
      ],
      "interpolate": false,
      "includeSpeedLimit": false,
      "travelMode": "driving"
    }
  ]
}

A snap to roads batchItem object can accept any of the supported snap to roads Request body

The batch should contain at least 1 query.

Batch Response Model

The batch response contains a summary component that indicates the totalRequests that were part of the original batch request and successfulRequests i.e. queries which were executed successfully. The batch response also includes a batchItems array which contains a response for each and every query in the batch request. The batchItems will contain the results in the exact same order the original queries were sent in the batch request. Each item is of one of the following types:

  • SnapToRoadsResponse - If the query completed successfully.

  • Error - If the query failed. The response will contain a code and a message in this case.

POST https://atlas.microsoft.com/route/snapToRoads:batch?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 Type Description
batchItems

SnapToRoadsBatchRequestItem[]

The list of queries to process.

Responses

Name Type Description
200 OK

SnapToRoadsBatchResponse

Batch request successfully processed. The response body contains all the batch results.

Other Status Codes

MapsErrorResponse

An unexpected error occurred.

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

A Snap To Roads Batch request containing 1 query

Sample request

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

{
  "batchItems": [
    {
      "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"
    },
    {
      "type": "FeatureCollection",
      "features": [
        {
          "type": "Feature",
          "geometry": {
            "coordinates": [
              -122.133269,
              47.6470965
            ],
            "type": "Point"
          },
          "properties": {}
        },
        {
          "type": "Feature",
          "geometry": {
            "coordinates": [
              -74.00487,
              40.71396
            ],
            "type": "Point"
          },
          "properties": {}
        }
      ],
      "travelMode": "driving"
    }
  ]
}

Sample response

{
  "summary": {
    "successfulRequests": 1,
    "totalRequests": 2
  },
  "batchItems": [
    {
      "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
          }
        }
      ]
    },
    {
      "error": {
        "code": "BadRequest",
        "message": "The distance between two consecutive points (-122.133269,47.6470965) (-74.00487,40.71396) must be within 2.5 kilometers of each other."
      }
    }
  ]
}

Definitions

Name Description
ErrorAdditionalInfo

The resource management error additional info.

ErrorDetail

The error detail.

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.

SnapToRoadsBatchRequestBody

The list of snap to roads queries/requests to process. The list can contain a max of 100 queries and must contain at least 1 query.

SnapToRoadsBatchRequestItem

Batch Query object

SnapToRoadsBatchResponse

This object is returned from a successful Snap To Roads Batch service call.

SnapToRoadsBatchResponseItem

Batch response item

SnapToRoadsFeatureProperties

Snap to Roads properties.

SnapToRoadsTravelModeEnum

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

ErrorAdditionalInfo

The resource management error additional info.

Name Type Description
info

object

The additional info.

type

string

The additional info type.

ErrorDetail

The error detail.

Name Type Description
additionalInfo

ErrorAdditionalInfo[]

The error additional info.

code

string

The error code.

details

ErrorDetail[]

The error details.

message

string

The error message.

target

string

The error target.

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.

SnapToRoadsBatchRequestBody

The list of snap to roads queries/requests to process. The list can contain a max of 100 queries and must contain at least 1 query.

Name Type Description
batchItems

SnapToRoadsBatchRequestItem[]

The list of queries to process.

SnapToRoadsBatchRequestItem

Batch Query object

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.

optionalId

string

Id of the request which would show in corresponding batchItem.

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.

SnapToRoadsBatchResponse

This object is returned from a successful Snap To Roads Batch service call.

Name Type Description
batchItems

SnapToRoadsBatchResponseItem[]

Array containing the batch results.

summary.successfulRequests

integer

Number of successful requests in the batch

summary.totalRequests

integer

Total number of requests in the batch

SnapToRoadsBatchResponseItem

Batch response item

Name Type Description
error

ErrorDetail

The error detail.

features

SnapToRoadFeaturesItem[]

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

optionalId

string

Id of the request which would show in corresponding batchItem.

type

FeatureTypeEnum

Specifies the GeoJSON type. The only supported object type is FeatureCollection. 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.

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.