我想通过谷歌方向API动态查询谷歌 map .例如,该请求计算从伊利诺伊州芝加哥到加利福尼亚州洛杉矶的路由,途经密苏里州乔普林和俄克拉何马州俄克拉荷马市的两个航路点:
它返回结果in the JSON format.
在Python中如何实现这一点?我想发送这样一个请求,接收结果并解析它.
我想通过谷歌方向API动态查询谷歌 map .例如,该请求计算从伊利诺伊州芝加哥到加利福尼亚州洛杉矶的路由,途经密苏里州乔普林和俄克拉何马州俄克拉荷马市的两个航路点:
它返回结果in the JSON format.
在Python中如何实现这一点?我想发送这样一个请求,接收结果并解析它.
我建议使用awesome requests库:
import requests
url = 'http://maps.googleapis.com/maps/api/directions/json'
params = dict(
origin='Chicago,IL',
destination='Los+Angeles,CA',
waypoints='Joplin,MO|Oklahoma+City,OK',
sensor='false'
)
resp = requests.get(url=url, params=params)
data = resp.json() # Check the JSON Response Content documentation below
JSON返回内容:https://requests.readthedocs.io/en/master/user/quickstart/#json-response-content