get elevation of a point using Azure maps

Hadi Moosavi 0 Reputation points
2024-10-19T03:06:04.93+00:00

I am working on a desktop app and I have been able to bring the map in the WPF window using Azure Maps. I am trying to get the elevation of a given point. I used the API call given in this article: https://techcommunity.microsoft.com/t5/azure-maps/preview-of-new-azure-maps-elevation-service-rest-apis/m-p/1957321/highlight/false#M47

But I am getting the error below when I debug the "HttpResponseMessage response" in my code.

response = {StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1,.....

my method goes like below (with the subscription key hidden)

private static string GetElevationFromCoordinates(double latitude, double longitude)
{
    string subscriptionKey = "myHiddenSubscriptionKey";
    string baseUrl = "https://atlas.microsoft.com/elevation/point/json";

    string url = $"{baseUrl}?api-version=1.0&subscription-key={subscriptionKey}&query={latitude},{longitude}";

    using (HttpClient client = new HttpClient())
    {
        HttpResponseMessage response = client.GetAsync(url).Result;
        response.EnsureSuccessStatusCode();

        string responseBody = response.Content.ReadAsStringAsync().Result;

        JObject json = JObject.Parse(responseBody);

        double elevation = json["data"]["elevationInMeters"].Value<double>();
        return $"Elevation: {elevation} meters";
    }
}
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,026 questions
Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
723 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.