I am facing this weird problem. I've been using the google maps APIs using javascript the whole while and now had to use google maps API using python for some reason.
The issue I'm facing is that I get different data in JS and python for the same source and destination. To be specific, I am not getting the path
variable in the response JSON when using python google maps.
import googlemaps
from datetime import datetime
gmaps = googlemaps.Client(key='API_KEY')
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))
now = datetime.now()
directions_result = gmaps.directions("Silk Board, Bengaluru", "Indira Nagar, Bengaluru", mode="transit", departure_time=now)
print(directions_result)
As you can see, the path
is missing.
I am using python-googlemaps' direction API. I also tried using request module and using the google direction API using https links but still the received data is the same. Is python supposed to behave this way or am I doing something wrong? Any help is appreciated.
CodePudding user response:
I contacted the google tech support and looks like the data is intended to be this way. If you want to get the co-ordinates of the entire route like I wanted, you can use the "polyline" field that comes in as a response.
The polyline will be in an encoded format. You can use this link to decode the data into the required co-ordinates or you can also use the polyline library(available in python) for the same.