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
Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
832 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. rbrundritt 20,836 Reputation points Microsoft Employee Moderator
    2024-10-21T16:39:41.5833333+00:00

    The elevation service in Azure Maps never made it to GA (general availability) and was instead deprecated as there was a lack of interest from customers. So it no longer exists.

    That said, there are many different ways to get elevation data depending on your need. If you simply need to get the elevation for individual points, there are a ton of options out there, especially if you are only focused on an individual country. For example, in the US, the USGS has high resolution elevation data available for the whole country (higher resolution that what was in Azure Maps). This is available as a REST service called "The National Map - Elevation Point Query Service" https://apps.nationalmap.gov/epqs/ You most likely will want the spatial reference identifier to be 4326, as this is for WGS84 latitude/longitude values which are used by Azure Maps and most other online maps (and GPS devices). This service makes use of the data from the USGS 3DEP program which has 0.5 meter resolution lidar data in some places which is significantly better than the 30 or 90 meter resolution data Azure Maps was using from NASA. Several other countries have similar 3D elevation programs.


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.