1

I am surprised whether i am doing any wrong or not. When i am finding the distance between two locations on google maps say maps.google.co.uk and when i query their API i get different result. Am i missing somethng?

Origin:Hyde Park Corner Station, Knightsbridge, London, United Kingdom Destination:The Ritz London, United Kingdom Result: 1.2 miles

And when i am using api:

http://maps.googleapis.com/maps/api/directions/json?origin=Hyde%20Park%20Corner%20Station,%20Knightsbridge,%20London,%20United%20Kingdom&destination=The%20Ritz%20London,%20United%20Kingdom&region=gb&sensor=false&alternatives=true&units=imperial

Result:4.3 miles or 5.0 miles etc.

Why is there so much of difference . Am i missing something.

Amazert
  • 21
  • 4
  • Your [first query (on maps.google.co.uk)](https://maps.google.co.uk/maps?saddr=Hyde+Park+Corner+Station,+Knightsbridge,+London,+United+Kingdom&daddr=The+Ritz+London,+United+Kingdom&hl=en&ll=51.505323,-0.150375&spn=0.128005,0.220757&sll=32.824552,-117.108978&sspn=0.691256,0.883026&geocode=%3BFfDvEQMd5tb9_yEUQAQegTVhWSlXyA_TKQV2SDEUQAQegTVhWQ&mra=mdsmb&disamb=0&t=m&z=12) doesn't return any route for me. – geocodezip Feb 06 '13 at 13:59
  • And there is always the [Google Maps Javascript API FAQ](https://developers.google.com/maps/faq#geocoder_differences) – geocodezip Feb 06 '13 at 14:20

1 Answers1

3

There are significant differences between Google Maps and a service like directions(or geocoding)

Google Maps at first is an implementation of Google Places, and that's the issue here. The directions-service uses geocoding to resolve the addresses, while Google Maps uses the PlacesService.

When you draw the route using the directionsRenderer, you will see that there are different start-and end-locations.

But when you first request the PlacesService to get the coordinates of the places, and use these coordinates to request the directionsService, you will get a result near by the result of Google Maps(the duration may differ, because the directionsService by default will not return results depending on the current traffic)

Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
  • is there any way to best way to fetch accurate distances same as available on maps.google.co.uk – Amazert Feb 06 '13 at 13:31
  • like I said in my answer, first request the coordinates from the placesService, and use these coordinates to request the directionsService – Dr.Molle Feb 06 '13 at 13:34
  • @Dr.Molle I am requesting using coordinates but still results are different https://stackoverflow.com/q/54269684/4685284 – Shahbaz Hashmi Jan 21 '19 at 07:53