none
DistanceMatrix REST API returning negative distances and times RRS feed

  • Question

  • Hi,

    I've been using the distance matrix API successfully for a few days, but I've just had a query that returns negative distances and times for all pairs.

    The query has one destination and multiple origins, the travelMode is set to 'driving' and the units requested are 'second' and 'km'. 

     The response seems to indicate success (status code is 200, status description is 'OK', authenticationResultCode is 'ValidCredentials'), but the distance and duration are negative for each cell. Here's the JSON for the first one:

                   {
                        "destinationIndex": 0,
                        "originIndex": 0,
                        "totalWalkDuration": 0,
                        "travelDistance": -1,
                        "travelDuration": -60
                    }

    Does anybody have any suggestions about how to figure out what's wrong here? I've fed the coordinates for the first origin-destination pair into the Route endpoint and it returns a valid route

    Thanks

    Matt

    Wednesday, December 20, 2017 2:52 PM

Answers

All replies

  • at are the origin and destination?

    [Blog] [twitter] [LinkedIn]

    Wednesday, December 20, 2017 3:14 PM
  • Hi Ricky,

    Thanks for the quick response. Using origin [51.9760199, -0.2622452] and destination [51.4769, 0.21073] demonstrates the problem.

    Here's the full JSON I'm posting:

    {

     "origins":[
      {
       "latitude":51.9760199,
       "longitude":-0.2622452
      }
     ],
     "destinations":[
      {
       "latitude":51.4769,
       "longitude":0.21073
      }
     ],
     "travelMode":"driving",
     "timeUnit":"second",
     "distanceUnit":"km"
    }

    Wednesday, December 20, 2017 3:49 PM
  • Ok, the first location is out in the middle of a field. I suspect that as a result a route isn't being calculated between the locations. When this happens negative values are returned for time and distance. This is documented here: https://msdn.microsoft.com/en-us/library/mt827296.aspx

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, December 20, 2017 6:01 PM
    • Marked as answer by Matt FS Thursday, December 21, 2017 1:20 PM
    Wednesday, December 20, 2017 6:01 PM
  • I was expecting the hasError member to be set, and totally missed the bit about negative time and distance, thanks for pointing it out.

    It's something to do with the destination, as no origin I tried works when fed into the DistanceMatrix endpoint - though they do work when fed into the Route endpoint. Now that I know what the behaviour means, I can fiddle with the destination location until something works.

    Thanks for your help

    Thursday, December 21, 2017 1:19 PM
  • Hi

    I've also experienced that distance matrix is replying with negative values.

    However I cannot figure out why. The addresses I use ought to be valid, and give valid results with some settings, and negative values with others.

    Using the Travelling Salesmen sample from BingMapsRESTToolkit I am able to get a valid answer for the addresses below if I for example select 

    • Waypoint Optimization: Travel Time
    • Travel Mode: Driving.

    However if I choose Travel Time, and Travel Mode == Walking, no route is displayed. And by single stepping through the code, I realized that it is because the distance matrix api is responding with negative values.

    Now, if I delete one of the addresses, so there only are 10 addresses, the api gives a valid result, and a route is displayed.

    Or if I keep the 11 addresses, and select Waypoint optimization == Straight Line Distance, and Travelmode still set to Walking I also get a valid result.

    I haven't been able to spot any error message in the distance matrix api response. It just return negative values.

    Addresses:

    Kildegade, Odder, Danmark
    Banegårdsgade, Odder, Danmark
    Præstevænget, Odder, Danmark
    Kløvermarksvej, Odder, Danmark
    Lundevej, Odder, Danmark
    Banegårdsparken, Odder, Danmark
    Østergade, Odder, Danmark
    Skovsangervej, Odder, Danmark
    Lundeparken, Odder, Danmark
    Mejerivej, Odder, Danmark
    Mørupsvej, Odder, Danmark


    Tuesday, March 20, 2018 6:56 PM