Search code examples
google-mapsgoogle-maps-api-3geocodinggoogle-geocoder

Google Maps Distance Matrix API returns different output compared to Google Maps


I am tinkering with Google Maps APIs using web services and noticed, that I get different output from Google Maps Distance Matrix API compared to Google Maps.

This is what I mean:
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Batilly&destinations=Cherbourg&language=en&key=AIzaSyAtYy7eYoooIzYGvFl15xRP2xHAdMU0-1c

this is what my query returns:

{
   "destination_addresses" : [ "Cherbourg, France" ],
   "origin_addresses" : [ "Batilly, France" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "195 km",
                  "value" : 194751
               },
               "duration" : {
                  "text" : "2 hours 3 mins",
                  "value" : 7373
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

And this is what Google Map returns: enter image description here

So instead of 708 kilometers I get 195 kilometers. The problem is with Batilly city. Cherbourg coordinates are good.

Real Coordingates of Batilly are 49.171029, 5.969359(Google Maps output)
Google Maps Geocoding returns 48.7486861, -0.14727

How should I configure my Google Maps Distance Matrix API so it would return the same output as Google maps does ?


Solution

  • There obviously are more than 1 city named Batilly in france.

    To get a result similar to Google Maps you may:

    1. get the location via a Places-TextSearch. For me it returns the desired location(49.1710200,5.9693580)
    2. use this location in the DistanceMatrix- request