Sample code for 30+ languages & platforms
Unicode C++ Requires Chilkat v11.6.0+

Azure Maps: Reverse-Geocode Coordinates

See more Azure Maps Examples

Finds address candidates for a longitude/latitude pair using Search 2026-01-01. The resultTypes filter requests a street address or populated place. An empty features array is a valid no-match result; the returned location does not establish a device's exact position.

Uses direct Chilkat.Http calls to the Azure public-cloud endpoint. Supply a nonempty subscription_key string in private qa_data/azure/maps.json. Shared-key authentication must be enabled on the Maps account. Keep this file outside source control and public web directories, and do not embed account keys in publicly distributed applications. Microsoft Entra ID is an alternative.

Query parameters are supplied as raw text for Chilkat to encode. The code checks transport status, HTTP status, and JSON parsing separately. For throttling or temporary service failures, use bounded retries and honor Retry-After. HTTP diagnostics can contain credentials and location data; inspect them privately. Calls use verified HTTPS and do not follow redirects.

Microsoft API reference

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkJsonObjectW.h>
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkJsonArrayW.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global.UnlockBundle for sample code.

    CkJsonObjectW config;
    config.put_Strict(true);
    //  Private file: {"subscription_key":"YOUR_AZURE_MAPS_KEY"}.
    success = config.LoadFile(L"qa_data/azure/maps.json");
    if (success != true) {
        wprintf(L"Could not load private Azure Maps configuration.\n");
        return;
    }

    if (config.JsonTypeOf(L"subscription_key") != 1) {
        wprintf(L"Missing or invalid subscription_key.\n");
        return;
    }

    if (config.StringOfEquals(L"subscription_key",L"",true) == true) {
        wprintf(L"A nonempty subscription_key is required.\n");
        return;
    }

    CkHttpW http;
    http.put_RequireSslCertVerify(true);
    http.put_FollowRedirects(false);
    http.put_ConnectTimeout(30);
    http.put_ReadTimeout(90);
    http.put_Accept(L"application/json");
    CkHttpResponseW response;
    CkJsonObjectW result;
    result.put_Strict(true);
    CkJsonObjectW query;
    //  Current Azure Maps operations accept the key as a header.
    http.SetRequestHeader(L"subscription-key",config.stringOf(L"subscription_key"));
    //  Search 2026 uses LONGITUDE first, LATITUDE second.
    query.UpdateString(L"api-version",L"2026-01-01");
    query.UpdateString(L"coordinates",L"-122.128275,47.639429");
    query.UpdateString(L"resultTypes",L"Address,PopulatedPlace");
    success = http.HttpParams(L"GET",L"https://atlas.microsoft.com/reverseGeocode",query,response);
    //  Http methods return false for HTTP errors as well as transport failures.
    if (response.get_StatusCode() == 0) {
        wprintf(L"No HTTP response. Inspect diagnostics privately; they can contain credentials.\n");
        return;
    }

    if (response.get_StatusCode() != 200) {
        wprintf(L"HTTP status: %d\n",response.get_StatusCode());
        wprintf(L"Error code: %s\n",response.getHeaderField(L"x-ms-error-code"));
        wprintf(L"Retry-After: %s\n",response.getHeaderField(L"Retry-After"));
        //  Correct 400/401/403 errors before retrying. Back off for 429 and transient 5xx.
        //  Keep response bodies and detailed diagnostics out of public logs.
        return;
    }

    if (success != true) {
        wprintf(L"The HTTP response was incomplete.\n");
        return;
    }

    success = result.Load(response.bodyStr());
    if (success != true) {
        wprintf(L"Expected a well-formed JSON response.\n");
        return;
    }

    CkJsonArrayW features;
    CkJsonObjectW feature;
    if (result.StringOfEquals(L"type",L"FeatureCollection",true) != true) {
        wprintf(L"Expected a GeoJSON FeatureCollection.\n");
        return;
    }

    success = result.ArrayOf2(L"features",features);
    if (success != true) {
        wprintf(L"Expected a features array.\n");
        return;
    }

    if (features.get_Size() == 0) {
        wprintf(L"No matching locations.\n");
        return;
    }

    int i = 0;
    while ((i < features.get_Size())) {
        success = features.ObjectAt2(i,feature);
        if (success != true) {
            wprintf(L"Invalid feature.\n");
            return;
        }

        if (feature.JsonTypeOf(L"properties.address.formattedAddress") != 1) {
            wprintf(L"Missing or invalid properties.address.formattedAddress.\n");
            return;
        }

        wprintf(L"Address: %s\n",feature.stringOf(L"properties.address.formattedAddress"));
        if (feature.JsonTypeOf(L"geometry.coordinates[0]") != 2) {
            wprintf(L"Missing or invalid geometry.coordinates[0].\n");
            return;
        }

        if (feature.JsonTypeOf(L"geometry.coordinates[1]") != 2) {
            wprintf(L"Missing or invalid geometry.coordinates[1].\n");
            return;
        }

        //  GeoJSON coordinates are longitude, latitude.
        wprintf(L"Longitude: %s\n",feature.stringOf(L"geometry.coordinates[0]"));
        wprintf(L"Latitude: %s\n",feature.stringOf(L"geometry.coordinates[1]"));
        if (feature.JsonTypeOf(L"properties.confidence") == 1) {
            wprintf(L"Confidence: %s\n",feature.stringOf(L"properties.confidence"));
        }

        i = i + 1;
    }
    }