Azure Maps API Guide

Azure Maps provides REST APIs for finding addresses and coordinates, calculating routes, retrieving map images and boundaries, and looking up time zones, weather, and IP address countries. Chilkat sends the HTTPS requests and reads the JSON or binary responses. This guide links to 13 complete examples using direct Chilkat.Http calls.

Getting started

The examples require an Azure Maps account, access to the selected service, and Chilkat 11.6.0 or later with the library unlocked. They use the Azure public-cloud endpoint https://atlas.microsoft.com. Azure Maps versions are selected per operation; a version used by Search is not necessarily valid for Weather or Render. See Microsoft's service and API version overview.

These are REST examples for applications that need location data or a downloaded map image. An interactive map with zooming, panning, and overlays also needs a map-rendering component. The static-map example saves an image without requiring an interactive map SDK.

API versions and coordinate order used by these examples
ServiceVersionCoordinate input
Geocoding, reverse geocoding, autocomplete, boundaries2026-01-01Longitude, latitude
Route directions and matrices2025-01-01GeoJSON arrays: longitude, latitude
Static maps2024-04-01Center: longitude, latitude; marker syntax also puts longitude first
Time zones1.0Query: latitude, longitude
Weather1.1Query: latitude, longitude
IP geolocation1.0An IPv4 or IPv6 address
Coordinate order matters. A longitude/latitude pair used with Search or Route must be reversed when forming the Timezone or Weather query. GeoJSON coordinates are longitude first. Keep these conversions explicit rather than passing the same coordinate string to every service.

How the HTTP requests map to Chilkat

Direct Http calls used throughout the examples
REST request or responseChilkat implementation
GET with query parametersBuild raw parameter values in a JsonObject, then call Http.HttpParams. Chilkat encodes them; do not pre-encode an address, coordinate string, or marker specification.
JSON POSTBuild the body with JsonObject and call Http.HttpJson. Search batches use application/json; the Route examples use application/geo+json.
OAuth token requestAdd form fields to HttpRequest, set POST and application/x-www-form-urlencoded, then call Http.HttpReq.
Authentication headersUse SetRequestHeader for subscription-key, or Http.AuthToken and the x-ms-client-id header for Entra authentication.
Polling a known operationUse Http.HttpNoBody for GET. SetUrlVar supplies the operation ID as a URL variable; keep IDs as strings.
JSON responseCheck HttpResponse.StatusCode, load BodyStr into JsonObject, and check the expected fields and types.
Map image responseCheck HTTP status and content type, then call HttpResponse.SaveBodyBinary. Do not decode image bytes as text.

These Http methods can return false for HTTP error responses as well as communication failures. A response status of zero indicates that no HTTP response was received. Inspect the status before deciding whether to parse a success response, report an API error, or handle a transport problem.

Authentication

Most examples load a nonempty string named subscription_key from qa_data/azure/maps.json and send it in the subscription-key header. This requires shared-key authentication to be enabled on the Maps account. Keep the configuration private and outside source control or public web directories. An account key must not be embedded in a publicly distributed application.

The Entra example obtains an application-only access token and then calls Geocoding. Its separate file, qa_data/azure/maps-entra.json, contains four nonempty strings:

tenant_id
The Entra directory ID or verified tenant domain used for the token endpoint.
client_id
The application registration's client ID.
client_secret
The application secret's value, not its identifier.
maps_client_id
The Azure Maps account's client ID, sent as x-ms-client-id. It is different from the application client ID.

Assign the application's service principal the necessary Maps data access at the account scope. The Azure Maps Search and Render Data Reader role covers the geocoding request shown. Other operations, including batches, require their corresponding data actions. Obtaining a token does not itself grant Maps permissions, and role changes can take time to propagate. See Azure Maps authentication and roles.

The token request uses grant_type=client_credentials and scope https://atlas.microsoft.com/.default. Cache the token privately and request another before it expires; this flow does not issue refresh tokens. A protected service or internal application can use this pattern without a webhook. Public applications need an appropriate delegated or backend arrangement. Managed identity is another option on supported Azure hosts. See the client credentials protocol.

Geocoding and Search

Geocoding turns an address into location candidates. Use either a free-form query or structured address fields such as addressLine, locality, and postalCode; do not combine the two forms. The existing address example now uses /geocode?api-version=2026-01-01. Its response is a GeoJSON FeatureCollection containing features, rather than the older Search v1 results array.

Check the candidate's formatted address, confidence, and match codes before accepting it. An empty features array is a valid no-match outcome. Geocoding does not certify postal deliverability. The main geometry is a display location; properties.geocodePoints can identify a separate point suitable for routing, such as an entrance. See Get Geocoding.

Reverse geocoding finds address information for a coordinate pair. Its result-type filter limits which kinds of locations can be returned, so a filtered request can legitimately have no match. See Get Reverse Geocoding.

The two synchronous batch examples send multiple requests in one JSON POST. Each batch accepts 1–100 inputs and returns results in the same order. Preserve that input-to-result mapping. HTTP 200 does not guarantee success for every item: inspect each item's error or features array. Split larger workloads into bounded batches. These synchronous operations do not provide a later result-retrieval URL. See forward batches and reverse batches.

Autocomplete takes partial text and a location bias: coordinates or a bounding box. A suggestion can have null geometry. After selection, geocode its formatted address if coordinates are needed. Interactive applications should debounce typing and ignore responses for superseded input. See Get Geocode Autocomplete.

Routing

The directions example sends two GeoJSON waypoints to Route 2025-01-01 and requests route geometry and an itinerary. Response features have different purposes: RoutePath contains route measurements and geometry, while ManeuverPoint contains navigation instructions. Select features by properties.type, not by assuming a fixed array position. The example prints plain-text instructions and saves the response to azure-maps-route.geojson.

The selected optimization is fastestWithoutTraffic. Adapt the travel mode and options when traffic estimates, walking, or truck restrictions matter. Distances are in meters and durations in seconds. Keep geographic coordinates in longitude/latitude order. See Post Route Directions.

A route matrix supplies travel measurements for each origin/destination pair. The example submits a two-by-two asynchronous matrix, saves Operation-Location in azure-maps-matrix-operation.json, and polls the status endpoint. HTTP 202 means accepted, not finished. The status operation distinguishes NotStarted, Running, Completed, and Failed; retrieve the result after completion. Read each cell's status and explicit indexes because a completed matrix can contain unsuccessful routes. See operation status.

Set resumeOperation to true to continue the saved job. The example stops after 30 polling attempts or when it reports a Retry-After instruction; resume later instead of submitting duplicate work. Run polling through a worker or scheduler so it does not block an application's interface. Retrieve results promptly: asynchronous results are retained for 24 hours. Matrix size and geographic constraints depend on request options; consult the async matrix limits before scaling the input.

The sample validates the operation URL against its fixed atlas.microsoft.com host and reconstructs the polling URLs. If using a geographic endpoint, configure the request endpoint and allowed polling host consistently with Microsoft's geographic scope documentation. Do not forward an account key to an arbitrary response URL.

Maps and Boundaries

The static-map example selects a road tileset, center, zoom, image size, and a numbered marker. It checks the response before saving the binary PNG as azure-maps-static.png. Supply marker syntax as raw query text and let Chilkat encode it. Preserve attribution when displaying or embedding the image. See Get Map Static Image.

The boundary example requests a locality outline at a coordinate. Unlike geocoding, this operation returns one GeoJSON Feature whose geometry is a GeometryCollection. It can contain multiple polygons or multipolygons, including separate areas and interior rings. Keep that structure intact. The example saves the whole feature, including attribution properties, as azure-maps-boundary.geojson.

Resolution controls boundary detail and output size. Choose the level appropriate for the application, and retain the returned provider credits when using the data. See Get Polygon. The saved map, route, boundary, and matrix files use the current working directory and replace same-named files on later runs.

Time Zone, Weather, and IP Location

The time-zone example returns the IANA zone ID, standard UTC offset, daylight-saving adjustment, and local time for coordinates. The effective offset combines the standard offset and daylight-saving adjustment. Store the zone ID for future scheduling rather than assuming today's offset will remain valid. The request omits timeStamp to use the current time; supply it when a particular date matters. See Timezone by Coordinates.

The weather example requests the latest compact observation in metric units. Read the observation timestamp and the unit accompanying each measurement. Missing or null temperature means unavailable, not zero. Change unit to imperial or request full details when needed. Weather coverage varies by location. Both this query and the time-zone query use latitude, longitude. See Current Conditions.

IP geolocation accepts IPv4 or IPv6 and returns a country/region ISO code. Special-purpose address ranges can return null country information. The result describes network location, which can differ from a user's location because of proxies, VPNs, or shared network egress. It is not a street address or GPS fix. See IP to Location.

Errors, retries, and application state

Check HTTP status, JSON validity, and operation-specific results separately. Review request parameters for HTTP 400 and authentication or account permissions for 401/403. For 429 and temporary service errors, honor Retry-After and use bounded backoff. An empty search result is not an authentication failure; a failed batch item is not necessarily a failed HTTP request.

If a matrix submission loses its response, the service may already have accepted it. Avoid blindly replaying the POST. Preserve known operation state, and resume polling when possible. Keep credentials, tokens, detailed diagnostics, and sensitive location data out of public logs. The examples enable HTTPS certificate verification and disable automatic redirects.