Get travel distance and travel time

Balasaheb Molawade 136 Reputation points
2024-08-07T10:13:29.0433333+00:00

Hi,

We have a requirement to calculate the travel distance and travel time for a collection of latitude/longitude coordinates. Sometimes, we will have around 400 latitude/longitude points.

We have used the below Bing Maps API, as shown below, to calculate the travel distance and travel time. However, this API has a limit of 24 points per request, so we need to loop through the collection and make multiple requests to obtain the cumulative travel distance and travel time.

https://dev.virtualearth.net/REST/v1/Routes?

This approach is time-consuming. Is there a more efficient solution for calculating travel distance and travel time using JavaScript?

Thanks!

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

1 answer

Sort by: Most helpful
  1. rbrundritt 17,166 Reputation points Microsoft Employee
    2024-08-07T17:17:31.2233333+00:00

    It depends on how your points are related. If you are trying to calculate all the distances between every combination of the points, then a Distance Matrix service is what you would want to use. Bing Maps has a Distance Matrix service: https://learn.microsoft.com/en-us/bingmaps/rest-services/routes/calculate-a-distance-matrix

    If you have a bunch of pairs of points and only need the travel information for the pairs, and not all combination of points, then a more efficient option would be the Azure Maps batch route service. Azure Maps has two variations of this service;

    If you just have a really long route that goes through 400 points in sequence, then Azure Maps is also a good option. I would recommend using the POST version of their Route Direction service so that your URL doesn't get too long and exceed browser limits. The Azure Maps route direction service supports up to 150 waypoints in a single request. In addition to that, if some of your points are "supporting points" meaning that you want the route to go through them but not stop there (e.g. kind of like route snapping), this service has no documented limit for supported points and I've used it with thousands (had a customer who wanted to snap GPS traces of garbage truck routes and also see the individual stops of the truck). https://learn.microsoft.com/en-us/rest/api/maps/route/post-route-directions?view=rest-maps-2024-04-01&tabs=HTTP

    There is a GET version of the route direction service but it doesn't have an option for supporting points: https://learn.microsoft.com/en-us/rest/api/maps/route/get-route-directions?view=rest-maps-2024-04-01&tabs=HTTP

    Azure Maps also has a Route matrix services, similar to Bing Maps:

    1 person found this answer 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.