7

I currently have an application which takes a a start and end point from a user and sends a request to the google maps directions API, for example: https://maps.googleapis.com/maps/api/directions/xml?key=my_key8&origin=M460PU&destination=NN36NW&sensor=false&mode=driving&units=imperial&departure_time=1501752779

We then display the estimated journey time for a given route. The user has asked if it's possible for us to include a link directly to Google maps so that they can see the route on the maps and make sure it looks ok.

I've seen previous questions such as this one: Link to Google Maps but that seems to be a solution for a simple Google Maps search, where as in my case I want to see a route from the directions API.

I'm trying to figure out if I there's a way I can take the data from the Directions API response and plug that in to a http://maps.google.com/maps URL that the user can click on. Has anyone ever had any success doing this?

xomena
  • 31,125
  • 6
  • 88
  • 117
Matt Watson
  • 5,065
  • 4
  • 30
  • 48
  • I can see there is one vote to close for being "too broad", if there's anything that could be more specific then let me know and I'll try to add it to the question. – Matt Watson Aug 03 '17 at 11:33
  • You can't display the returned route on Google Maps directly. Your options are a Google Maps JavaScript API v3 map or a Static Map (both of which are covered by pre-existing questions). – geocodezip Aug 03 '17 at 12:50

1 Answers1

4

As mentioned @geocodezip you should use Google Maps JavaScript API or Google Static Maps API in order to show exactly the same route as the output of Directions API.

There is also an option to open Google Maps web site or native app using the Google Maps URLs. You can have a look at the documentation to figure out how to create the URL:

https://developers.google.com/maps/documentation/urls/guide#directions-action

The only issue is that the Google Maps URLs doesn't provide any parameter for departure time, so you will always get routes for "Leave now" that might have discrepancies comparing to a web service that was requested for a different departure time.

Based on your question I think the Google Maps URL might be

https://www.google.com/maps/dir/?api=1&origin=M460PU&destination=NN36NW&travelmode=driving

xomena
  • 31,125
  • 6
  • 88
  • 117