1

When I use the Google Maps directions API (server-side) the distance and duration are almost always different then the embedded (iframe) maps tells me.

I use the embedded version to show to the customer, and I use the API version to calculate the taxi price. It is therefore necessary that I get the same distance and duration from both services.

I am using the following origin address: Straße des 17. Juni, Berlin, Germany

I am using the following destination address: Amsterdam Airport Schiphol, Netherlands

With the above route, this is the output:

Embedded (iframe): 6 hours 31 mins - 661km

API (server-side): 6 hours 3 mins - 662km

Directions API: https://developers.google.com/maps/documentation/directions/

Directions Embed: https://developers.google.com/maps/documentation/embed/start

Hope somebody can help me out.

Tijme
  • 39
  • 2
  • 24
  • 41

1 Answers1

2

Different distance:

the embedded changes your destination to "Schiphol Amsterdam Airport, Evert van de Beekstraat 202, 1118 CP Schiphol, Netherlands" while the API call leaves it exactly like you entered it. The resulting coordinates are different

API call with exact string

API call with slightly modified destination

Different time:

Looks like the embed is taking into account traffic conditions and departure_time and the API call does not. Are you using an API key?

For driving directions: Google Maps API for Work customers can specify the departure_time to receive trip duration considering current traffic conditions

aergistal
  • 29,947
  • 5
  • 70
  • 92
  • Yes, I am using API keys. Browser key for the embedded version and Server key for the API version. Hope you can help. – Tijme Mar 13 '15 at 13:27
  • Do you have a regular key or an API for Work key? Try to change **departure_time** in the API call and see if the time changes. It's epoch or "now". – aergistal Mar 13 '15 at 13:54
  • I have two keys (browser and server). I created these in the Google Developer Console. I use the server key for the server-side api call and I use the browser key for the client-side embedded map. I know for sure these keys are working, because without them, I get errors. Setting departure_time to now unfortunately doesn't work. – Tijme Mar 13 '15 at 16:07
  • If you didn't pay for them then they're regular keys, not Enterprise key. If I understand correctly from their docs (see quote in my answer), you cannot use `departure_time` without a paid key. Which in turn explains the time differences between the embedded app and the API call. Maybe someone can confirm, as I don't own a Work API key. – aergistal Mar 13 '15 at 16:10
  • 1
    Ah ok, hope somebody can confirm, before buying an enterprise key. – Tijme Mar 13 '15 at 16:16
  • See [this](http://www.reddit.com/r/tasker/comments/2un7ab/help_getting_driving_traffic_estimate_times_using/coa0unq) and [this](http://stackoverflow.com/questions/18661186/google-maps-api-use-departure-time-in-distancematrix) for more evidence that **departure_time** doesn't work without a business key. This means the value you get with a free key is some kind of average. The embedded version works because it taps directly into the Google API. With this I think I answered all the points in your original question. – aergistal Mar 14 '15 at 12:07
  • Ok thanks. Is there any way I can turn of live traffic in the embedded version, so that I get the same results from both services? – Tijme Mar 14 '15 at 21:10
  • Don't think so, it's not among the parameters for the embedded version. The value just defaults to "now" – aergistal Mar 14 '15 at 21:33