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 |
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.
|
|
type | True |
Specifies the |
|
includeSpeedLimit |
boolean |
Specifies whether to include speed limit information for the snapped points in the response. The unit is in kilometers per hour.
|
|
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 |
|
travelMode |
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 |
OK Media Types: "application/geo+json", "application/json" |
|
Other Status Codes |
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 |
---|---|
Features |
Specifies the |
Feature |
Specifies the |
Geo |
A valid |
Input |
Specifies the input snap to roads points. |
Maps |
The error detail. |
Maps |
Common error response for Azure Maps APIs to return error details for failed operations. |
Maps |
An object containing more specific information than the current object about the error. |
Point |
The origin point passed as a valid
|
Snap |
GeoJSON feature object that contains Geometry object and additional properties of the route. |
Snap |
Snap to Roads properties. |
Snap |
This object is the request body. |
Snap |
This object is returned from a successful call. |
Snap |
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 |
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 |
GeoJsonPoint
A valid GeoJSON Point
geometry type. Please refer to RFC 7946 for details.
Name | Type | Description |
---|---|---|
coordinates |
number[] |
A |
type |
string:
Point |
Specifies the |
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: |
A valid |
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 |
Specifies the |
MapsErrorDetail
The error detail.
Name | Type | Description |
---|---|---|
code |
string |
One of a server-defined set of error codes. |
details |
An array of details about specific errors that led to this reported error. |
|
innererror |
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 |
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 |
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 |
type |
string:
Point |
Specifies the geometry type for the |
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: |
A valid |
properties |
Snap to Roads properties. |
|
type |
Specifies the |
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 |
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.
|
||
includeSpeedLimit |
boolean |
False |
Specifies whether to include speed limit information for the snapped points in the response. The unit is in kilometers per hour.
|
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 |
travelMode | 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 |
Specifies the |
SnapToRoadsResponse
This object is returned from a successful call.
Name | Type | Description |
---|---|---|
features |
|
|
type |
Specifies the |
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. |