4

I simply want to use Google Directions API to get the route/directions from point A to point B, given the lat/long coordinates of A and B. And I want to do this in Python.

If I do something like that, it works:

import googlemaps
gmaps = googlemaps.Client(key='mykey')
start = 'Constitution Ave NW & 10th St NW, Washington, DC'
end   = 'Independence and 6th SW, Washington, DC 20024, USA'
dirs  = gmaps.directions(start, end)

However, this is not what I want since I've only got lat/long coordinates and not the addresses. I know that I can convert lat/long to addresses using reverse_geocode(), but this is not what I want since that would be calling the Geocoding API on top of the Directions API. I haven't found a way to use gmaps.directions() on lat/long directly.

So my question is simple: Can I use the Directions API alone to get directions from point A to point B when I only have lat/long coordinates for A and B? Or am I obliged to use the Geocoding API on top of it?

Thank you for your time.

en1
  • 237
  • 4
  • 8

3 Answers3

2

According to the Developer's Guide from Google:

If you pass coordinates, they are used unchanged to calculate directions. Ensure that no space exists between the latitude and longitude values.
origin=41.43206,-81.38992

Soldeplata Saketos
  • 3,212
  • 1
  • 25
  • 38
0

Please use following way to giving the latitude and langitude. So hope it will be helpful:

origin: {lat:19.99, lng:73.78},  // Start Point
destination: {lat:19.697316, lng:73.560936},  // End Point
Hexfire
  • 5,945
  • 8
  • 32
  • 42
0

this is your code adapted to coordinates. Note that you cannot mix coordinates and string adresses

import googlemaps
gmaps = googlemaps.Client(key='mykey')
start = '43.70721,-79.3955999'
end   = '43.7077599,-79.39294'
dirs  = gmaps.directions(start, end)
Macumbaomuerte
  • 2,197
  • 2
  • 19
  • 22