Spatial - Post Closest Point

Use to get the closest point between a base point and a given set of target points.

The Post Closest Point API is an HTTP POST request that returns the closest point between a base point and a given set of target points. The set of target points is provided by user data in post request body. The user data may only contain a collection of Point geometry. MultiPoint or other geometries will be ignored if provided. The algorithm does not take into account routing or traffic. The maximum number of points accepted is 100,000. Information returned includes closest point latitude, longitude, and distance in meters from the closest point.

POST https://{geography}.atlas.microsoft.com/spatial/closestPoint/json?api-version=2022-08-01&lat={lat}&lon={lon}
POST https://{geography}.atlas.microsoft.com/spatial/closestPoint/json?api-version=2022-08-01&lat={lat}&lon={lon}&numberOfClosestPoints={numberOfClosestPoints}

URI Parameters

Name In Required Type Description
format
path True

JsonFormat

Desired format of the response. Only json format is supported.

geography
path True

string

Location of the Azure Maps Account. Valid values are us (East US, West Central US, West US 2) and eu (North Europe, West Europe). This parameter is required when a udid is supplied in the request. For example, if the Azure Maps Account is located in East US, only requests to us geography will be accepted.

api-version
query True

string

Version number of Azure Maps API.

lat
query True

number

The latitude of the location being passed. Example: 48.36.

lon
query True

number

The longitude of the location being passed. Example: -124.63.

numberOfClosestPoints
query

integer

The number of closest points expected from response. Default: 1, minimum: 1 and maximum: 50

Request Header

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.

Request Body

Name Required Type Description
features True

GeoJsonFeature[]

Contains a list of valid GeoJSON Feature objects.

type True string:

FeatureCollection

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

Responses

Name Type Description
200 OK

ClosestPointResponse

OK

Other Status Codes

ErrorResponse

An unexpected error occurred.

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.

Notes

  • 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.

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

PostClosestPoint

Sample Request

POST https://us.atlas.microsoft.com/spatial/closestPoint/json?api-version=2022-08-01&lat=47.622942&lon=-122.316456

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "geometryId": 1001
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          -105.02860293715861,
          40.51615340677395
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "geometryId": 1002
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          -105.02860381672178,
          40.51599099003731
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "geometryId": 1003
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          -105.02812292879467,
          40.51605867808856
        ]
      }
    }
  ]
}

Sample Response

{
  "summary": {
    "sourcePoint": {
      "lat": 47.622942,
      "lon": -122.316456
    },
    "udid": null,
    "information": "3 points processed in user data"
  },
  "result": [
    {
      "distanceInMeters": 1587492.66,
      "position": {
        "lat": 40.51615340677395,
        "lon": -105.02860293715861
      },
      "geometryId": "1001"
    }
  ]
}

Definitions

Name Description
ClosestPoint

Closest Point Result Entry Object

ClosestPointResponse

This object is returned from a successful Spatial Closest Point call

ClosestPointSummary

Closest Point Summary object

ErrorAdditionalInfo

The resource management error additional info.

ErrorDetail

The error detail.

ErrorResponse

Error response

GeoJsonFeature

A valid GeoJSON Feature object type. Please refer to RFC 7946 for details.

GeoJsonFeatureCollection

A valid GeoJSON FeatureCollection object type. Please refer to RFC 7946 for details.

GeoJsonGeometry

A valid GeoJSON geometry object. The type must be one of the seven valid GeoJSON geometry types - Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon and GeometryCollection. Please refer to RFC 7946 for details.

GeoJsonGeometryCollection

A valid GeoJSON GeometryCollection object type. Please refer to RFC 7946 for details.

GeoJsonLineString

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

GeoJsonMultiLineString

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

GeoJsonMultiPoint

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

GeoJsonMultiPolygon

A valid GeoJSON MultiPolygon object type. Please refer to RFC 7946 for details.

GeoJsonPoint

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

GeoJsonPolygon

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

JsonFormat

Desired format of the response. Only json format is supported.

LatLongPairAbbreviated

A location represented as a latitude and longitude using short names 'lat' & 'lon'.

ClosestPoint

Closest Point Result Entry Object

Name Type Description
distanceInMeters

number

The distance in meters from the source point to the closest point

geometryId

string

The unique id identifies a geometry

position

LatLongPairAbbreviated

A location represented as a latitude and longitude using short names 'lat' & 'lon'.

ClosestPointResponse

This object is returned from a successful Spatial Closest Point call

Name Type Description
result

ClosestPoint[]

Closest Point Result Array

summary

ClosestPointSummary

Closest Point Summary object

ClosestPointSummary

Closest Point Summary object

Name Type Description
information

string

Processing information

sourcePoint

LatLongPairAbbreviated

A location represented as a latitude and longitude using short names 'lat' & 'lon'.

udid

string

A unique data id (udid) for the uploaded content

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.

ErrorResponse

Error response

Name Type Description
error

ErrorDetail

The error object.

GeoJsonFeature

A valid GeoJSON Feature object type. Please refer to RFC 7946 for details.

Name Type Description
featureType

string

The type of the feature. The value depends on the data model the current feature is part of. Some data models may have an empty value.

geometry GeoJsonGeometry:

A valid GeoJSON geometry object. The type must be one of the seven valid GeoJSON geometry types - Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon and GeometryCollection. Please refer to RFC 7946 for details.

id

string

Identifier for the feature.

type string:

Feature

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

GeoJsonFeatureCollection

A valid GeoJSON FeatureCollection object type. Please refer to RFC 7946 for details.

Name Type Description
features

GeoJsonFeature[]

Contains a list of valid GeoJSON Feature objects.

type string:

FeatureCollection

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

GeoJsonGeometry

A valid GeoJSON geometry object. The type must be one of the seven valid GeoJSON geometry types - Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon and GeometryCollection. Please refer to RFC 7946 for details.

Name Type Description
type

GeoJsonObjectType

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

GeoJsonGeometryCollection

A valid GeoJSON GeometryCollection object type. Please refer to RFC 7946 for details.

Name Type Description
geometries GeoJsonGeometry[]:

Contains a list of valid GeoJSON geometry objects. Note that coordinates in GeoJSON are in x, y order (longitude, latitude).

type string:

GeometryCollection

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

GeoJsonLineString

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

Name Type Description
coordinates

number[]

Coordinates for the GeoJson LineString geometry.

type string:

LineString

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

GeoJsonMultiLineString

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

Name Type Description
coordinates

number[]

Coordinates for the GeoJson MultiLineString geometry.

type string:

MultiLineString

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

GeoJsonMultiPoint

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

Name Type Description
coordinates

number[]

Coordinates for the GeoJson MultiPoint geometry.

type string:

MultiPoint

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

GeoJsonMultiPolygon

A valid GeoJSON MultiPolygon object type. Please refer to RFC 7946 for details.

Name Type Description
coordinates

number[]

Contains a list of valid GeoJSON Polygon objects. Note that coordinates in GeoJSON are in x, y order (longitude, latitude).

type string:

MultiPolygon

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

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.

GeoJsonPolygon

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

Name Type Description
coordinates

number[]

Coordinates for the GeoJson Polygon geometry type.

type string:

Polygon

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

JsonFormat

Desired format of the response. Only json format is supported.

Name Type Description
json

string

The JavaScript Object Notation Data Interchange Format

LatLongPairAbbreviated

A location represented as a latitude and longitude using short names 'lat' & 'lon'.

Name Type Description
lat

number

Latitude property

lon

number

Longitude property