Patrick
Patrick

Reputation: 2781

Google Distance Matrix using Microsoft Bing Maps

Is there a way to use Bing Maps Driving REST Service the same way we use Google Distance Matrix?

I want to be able to calculate the distance:

p1 -> p2 
p1 -> p3
p1 -> p4
   ... 
p1 -> p15

With Google Distance Matrix I am able to get the distance for the 15 routes with one request, but using Bing I don't find a way to do it (only with 15 requests for each distance calculation).

Upvotes: 0

Views: 1484

Answers (1)

rbrundritt
rbrundritt

Reputation: 18013

Bing Maps does not expose a distance Matrix API, however it is possible to generate the required data using the Bing Maps Routing Service. You could make a request for each distance but this would be slow and generate a lot of transactions. The Bing Maps Routing Service allows you to pass in up to 25 waypoints into a single request. As such you can use this to do a batch calculation. For example, lets say we have 3 locations. A matrix would be 3x3 = 9 cells, 3 of these would have a value of 0 (i.e. A -> A). This leaves 6 cells that need calculations. To further optimize would could assume the distance between two locations is the same regardless of the direction of travel (i.e. A -> B = B -> A). If we make this assumption we only need to calculate the values for 3 cells; A-> B, A-> C, B-> C. To further optimize the route calculation we could align the waypoints such that we minimize the number of extra calculations done; A -> B, B -> C, C -> A. By doing this we can then calculate a route from A -> B -> C -> A. This would be a route with only 4 waypoints. The route response will then contain an array of route legs, each having a defined distance and time value which you can use to generate your matrix.

In your case you are only calculating from one location to 15 others. This is a 2 x 15 matrix and a bit similar than the above method to accomplish. In this case you can calculate a multi-waypoint route back and forth from the start point and each waypoint. Lets say the start is S and the other points are A, B, C, we could calculate a route from S -> A -> S -> B -> S -> C. This response for the route would have an array of route legs. The odd indexed route legs in the array would have your distance/times from S -> (A,B,C). Using this method you could calculate the data you need from S to 11 other locations. If you have 15 locations you would need to make two route requests. Note that if you are doing this while displaying an interactive map you can generate a session key from the map and use that in the request o make the route calls non-billable.

I'm assuming you want to do this so that you can calculate an optimized route using a traveling salesmen algorithm. If this is the case you might find this code sample interesting: https://code.msdn.microsoft.com/windowsapps/Bing-Maps-trip-optimizer-c4e037f7

Upvotes: 2

Related Questions