Bing Maps API - Finding Distance between 2 points - Invalid Credentials Status Code 401

Paul Schonier 20 Reputation points
2024-06-04T15:27:40.5466667+00:00

I am trying to send an HTTP request to the bing maps API using a developer key in order to determine the distance between 2 lat/long points contained in a SharePoint list and a fixed position (Shop Location). I am using postman to submit the following:

https://dev.virtualearth.net/REST/v1/Routes/Driving?wp.0={32.6115970189768},{-103.459926710573}&wp.1={31.95798907675224},{-102.26350610450459}&key={MyBingMapsKey}

I am getting access denied for some reason even though there doesn't appear to be any issue with the key I created to test this process:

    "errorDetails": [

        "Access was denied. You may have entered your credentials incorrectly, or you might not have access to the requested resource or operation."

    ],

    "resourceSets": [],

    "statusCode": 401,

    "statusDescription": "Unauthorized",

    "traceId": "ae6a3e81b9a06c6539011c9cf2980a20"

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
742 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,904 questions
Windows Maps
Windows Maps
A Microsoft app that provides voice navigation and turn-by-turn driving, transit, and walking directions.
257 questions
0 comments No comments
{count} votes

Accepted answer
  1. rbrundritt 18,686 Reputation points Microsoft Employee
    2024-06-05T15:04:31.24+00:00

    Remove the squirrely braces from your query {, }. Your URL should look like this:

    https://dev.virtualearth.net/REST/v1/Routes/Driving?wp.0=32.6115970189768,-103.459926710573&wp.1=31.95798907675224,-102.26350610450459&key=<YourBingMapsKey>

    Be sure to replace <YourBingMapsKey> with your Bing Maps key. Note this service calculates driving distances between points.

    That said, I would highly recommend using Azure Maps instead. Bing Maps Enterprise platform announced its retirement a couple weeks ago and is directing customers to Azure Maps: https://azure.microsoft.com/en-us/blog/azure-maps-reimagining-location-services-with-cloud-and-ai-innovation/

    To get driving distances between points Azure Maps has several services you can use:

    All of the above is for driving distances/travel times. If you only need straight line distances that are a couple of options:

    1. Use the Haversine formula in code, as doing this in code would not have any additional costs. It is a relatively simple calculation that is commonly used for straight line distances between coordinates. You can find code for this in a lot of different programming languages here: https://rosettacode.org/wiki/Haversine_formula
    2. There is the Great Circle Distance API in Azure Maps if you need to use a REST API: https://learn.microsoft.com/en-us/rest/api/maps/spatial/get-great-circle-distance?view=rest-maps-2023-06-01&tabs=HTTP
    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

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.