我正面臨這個奇怪的問題。我一直在使用使用 javascript 的谷歌地圖 API,現在由于某種原因不得不使用 python 使用谷歌地圖 API。我面臨的問題是我在 JS 和 python 中為相同的源和目標獲得了不同的資料。具體來說,path在使用 python 谷歌地圖時,我沒有在回應 JSON 中獲取變數。
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)
我使用python獲得的資料: 
我使用 JS 得到的資料:
如您所見,path缺少了。
我正在使用python-googlemaps 的方向 API。我還嘗試使用請求模塊和使用 https 鏈接的谷歌方向 API,但接收到的資料仍然相同。python應該這樣做還是我做錯了什么?任何幫助表示贊賞。
uj5u.com熱心網友回復:
我聯系了谷歌技術支持,看起來資料是這樣的。如果您想像我想要的那樣獲得整個路線的坐標,您可以使用作為回應出現的“折線”欄位。
折線將采用編碼格式。您可以使用此鏈接將資料解碼為所需的坐標,或者您也可以使用折線庫(python 中可用)進行相同的操作。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/392427.html
標籤:Python 谷歌地图 google-maps-api-3 google-directions-api
