【发布时间】:2022-01-21 20:35:40
【问题描述】:
我正面临这个奇怪的问题。我一直在使用 javascript 使用谷歌地图 API,现在由于某种原因不得不使用 python 使用谷歌地图 API。
我面临的问题是我在 JS 和 python 中为相同的源和目标获得了不同的数据。具体来说,在使用 python 谷歌地图时,我没有在响应 JSON 中获得 path 变量。
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)
如您所见,path 不见了。
我正在使用python-googlemaps' 方向API。 我还尝试使用请求模块并使用 https 链接使用谷歌方向 API,但接收到的数据仍然是相同的。 python应该以这种方式表现还是我做错了什么?任何帮助表示赞赏。
【问题讨论】:
-
你是如何使用JS调用API的?
-
我使用 googleapis.com 作为我的来源。类似于此link。
-
你能分享你的 Python 调用吗?请记住删除您的 API 密钥
-
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)我尝试将模式更改为“驾驶”,因为那是我在 JS 中使用的 -
你试过
mode="driving"吗?
标签: python google-maps google-maps-api-3 google-directions-api