none
Distance matrix RRS feed

  • Question

  • Hi,

    We have below requirement. 

    We have 10 customers on different location and we want meet them in next 3 days so we want to build the schedule for them based on location. We want optimize schedule. 

    Can we used Distance matrix API to achieve above requirement and how.

    Is anyone have example where you used distance matrix api.

    Thanks!


    Balasaheb

    Saturday, June 2, 2018 12:38 PM

Answers

All replies

  • Hi Balasaheb,

    The distance matrix API description is available here (https://www.microsoft.com/en-us/maps/distance-matrix) and it has some suggested samples noted.  If you want your customers to travel to the same place at the same time, you likely just want to research the different route timings for each to leave and arrive at the same location at the same time.

    Sincerely,

    IoTGirl

    Sunday, June 3, 2018 1:51 AM
    Owner
  • Hi,

    Thanks for your reply. We have already gone through the link you provided.

    We have written following code to get the distance matrix.

     var orglat = 19.0760;
               var orglong =72.8777;
               var dist1lat =17.6805;
               var dist1long = 74.0183;
               var dist2lat = 22.5726;
               var dist2long = 88.3639;
               var dist3lat = 16.7050;
               var dist3long = 74.2433;
               var travelMode = "driving";


               var url = "https://dev.virtualearth.net/REST/v1/Routes/DistanceMatrix?origins=" + orglat + "," + orglong +
                   "&destinations=" + dist1lat + "," + dist1long + ";" + dist2lat + "," + dist2long + ";" + dist3lat + "," + dist3long +
                   "&travelMode="+travelMode+"&key=" + BingMapsKey;  

               var req = new XMLHttpRequest();
               req.open("GET", encodeURI(url), true);
               req.setRequestHeader("Accept", "application/json");
               req.onreadystatechange = function () {
                   if (this.readyState == 4 /* complete */) {
                       req.onreadystatechange = null;
                       alert("Sucess " + req.response);
                   }
               };
               req.send(null);

    Then it return below response. As per our understanding it should give the destinationIndex 2 as place of destinationIndex 1 because dist3lat,dist3long is closer to origin then dist2lat,dist2long.

    Response:

    ""authenticationResultCode":"ValidCredentials","brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png","copyright":"Copyright © 2018 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","resourceSets":[{"estimatedTotal":1,"resources":[{"__type":"DistanceMatrix:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1","destinations":[{"latitude":17.6805,"longitude":74.0183},{"latitude":22.5726,"longitude":88.3639},{"latitude":16.705,"longitude":74.2433}],"errorMessage":"Request accepted.","origins":[{"latitude":19.076,"longitude":72.8777}],"results":[{"destinationIndex":0,"originIndex":0,"totalWalkDuration":0,"travelDistance":252.780916666667,"travelDuration":162.183333333333},{"destinationIndex":1,"originIndex":0,"totalWalkDuration":0,"travelDistance":1938.41788888889,"travelDuration":1403.475},{"destinationIndex":2,"originIndex":0,"totalWalkDuration":0,"travelDistance":372.993777777778,"travelDuration":243.845}]}]}],"statusCode":200,"statusDescription":"OK","traceId":"603a5525cace4a8d8a6ac1906b0b1e53|HK20290124|7.7.0.0"}"

    Can you please let us know how we do this or it will return the response as shown above.

    We want it should display optimize route as shown below

    Origin -> Destination 1 ->  Destination 3 -> Destination 2

    Waiting for your reply.

    Thanks!

                       

    Balasaheb


    Monday, June 4, 2018 10:41 AM
  • The distance matrix API doesn't do any waypoint optimizations/reordering. The order of the cells in the matrix is random as each cell is calculated in parallel asynchronously. If you want the optimized order for shortest travel time/distance you would apply use this data in a travelling salesmen algorithm. The Bing Maps REST toolkit (https://github.com/Microsoft/BingMapsRESTToolkit) has an extension built in for this. You can either simply calculate a route and set the WaypointOptimization option. Alternatively, if you don't want to calculate the route and simply want the order of the waypoints you can use the TravellingSalesmen class. Here is documentation: https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/Getting%20Started.md#TravellingSalesmen

    [Blog] [twitter] [LinkedIn]

    Monday, June 4, 2018 4:51 PM
  • Hi Ricky,

    Thanks for your reply. We got it.

    We are getting error while build the project downloaded from GitHub.

    Can you please let us know any prerequisite require to run this project.

    Also Let us what DLL or reference required to execute the code given in below link.

    https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/Getting%20Started.md#TravellingSalesmen

    Waiting for your reply.

    Thanks!


    Balasaheb

    Tuesday, June 5, 2018 12:38 PM
  • What error are you seeing? Don't download the GitHub project, add the library to your project using the NuGet package.

    If you want an easier solution for optimizing waypoints, consider using Azure Maps instead. The routing service in that platform provides this functionality out of the box. Here is some resources:

    Code sample: https://azuremapscodesamples.azurewebsites.net/#Waypoint%20Optimization

    Documentation: https://docs.microsoft.com/en-us/azure/azure-maps/index

    Main landing page: https://azure.com/maps


    [Blog] [twitter] [LinkedIn]


    Tuesday, June 5, 2018 4:01 PM
  • Hi Ricky,

    We want your help to achieve below requirement.

    We have set of records say suppose 100. and We want to generate schedule for this records in optimized way. Also we want to add some constraint like work time say suppose 8:00 AM to 5:00 or number of visit will be 5 per day. We want to show route on map.

    Can you suggest which method should we follow to achieve this. 

    Thanks!


    Balasaheb

    Tuesday, June 19, 2018 1:01 PM
  • Hi,

    Anyone have time to go though our requirement and have suggestion for it.

    Thanks


    Balasaheb

    Saturday, June 23, 2018 6:28 PM