Bing Maps API - avoid not working in DistanceMatrix

Miras 20 Reputation points
2024-01-26T16:04:20.6866667+00:00

Hello,

I am trying to write a function in Excel in VBA that returns the distance of a car journey between two points. Generally it works but I cannot apply exclusions in the query using "avoid" such as avoid highways, tolls ferry, minimizeHighways, minimizeTolls, borderCrossing. Using these does not generate any errors but does not change the route distance in any way. Distance is still the same. Although when I use BingMaps www.bing.com/maps as standard and I use one of the above options the route distance changes. What am I doing wrong?

Public Function GetDistance(start As String, dest As String, key As String)

Dim firstVal As String, secondVal As String, lastVal As String

firstVal = "https://dev.virtualearth.net/REST/v1/Routes/DistanceMatrix?origins="

secondVal = "&destinations="

lastVal = "&travelMode=driving&o=xml&key=" & key & "&avoid=minimizeTolls,highways,minimizeHighways"

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")

Url = firstVal & start & secondVal & dest & lastVal

objHTTP.Open "GET", Url, False

objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"

objHTTP.send ("")

GetDistance = WorksheetFunction.FilterXML(objHTTP.responseText, "//TravelDistance")

End Function

Thanks in advance for any help

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
786 questions
0 comments No comments
{count} votes

Accepted answer
  1. rbrundritt 19,126 Reputation points Microsoft Employee
    2024-01-26T17:09:08.3066667+00:00

    The distance matrix API doesn't have an "avoid" option. If you include it in the query, it is simply ignored. If you look at the documentation here: https://learn.microsoft.com/en-us/bingmaps/rest-services/routes/calculate-a-distance-matrix you will see that this API has only the following options: origins, destinations, travelMode, startTime, endTime, resolution, distanceUnit, timeUnit

    If you need a distance matrix service that supports "avoid" consider using Azure Maps: https://learn.microsoft.com/en-us/rest/api/maps/route/post-route-matrix?view=rest-maps-2023-06-01&tabs=HTTP It's distance/route matrix API has a lot more options.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

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.