Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 856
Evaldas B Avatar asked Feb 05 '26 14:02

Evaldas B


1 Answers

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
like image 186
Dr.Molle Avatar answered Feb 09 '26 01:02

Dr.Molle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!