Python 有api给我一份从a市到B市的旅行路线表吗

Python 有api给我一份从a市到B市的旅行路线表吗,python,maps,directions,Python,Maps,Directions,所以我有一个python程序,它输入了城市A和城市B的经纬度。有没有一个api可以输出从城市A到城市B的一系列方向。像这样的输出: Turn right on South DeAnza Blvd and then make a turn........ This is your destination. 有人能给我一些指导吗?非常感谢您的帮助。您可以使用 谷歌方向API是一个计算方向的服务 在使用HTTP请求的位置之间 一个简单的例子: import urllib2 import json

所以我有一个python程序,它输入了城市A和城市B的经纬度。有没有一个api可以输出从城市A到城市B的一系列方向。像这样的输出:

Turn right on South DeAnza Blvd and then make a turn........ This is your destination.
有人能给我一些指导吗?非常感谢您的帮助。

您可以使用

谷歌方向API是一个计算方向的服务 在使用HTTP请求的位置之间

一个简单的例子:

import urllib2
import json

url = "https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal"
response = urllib2.urlopen(url)
j = json.loads(response.read())

for step in j['routes'][0]['legs'][0]['steps']:
    print step['html_instructions']
产出:

Head <b>north</b> on <b>Bay St</b> toward <b>Hagerman St</b>
Turn <b>right</b> onto <b>Dundas St W</b>
Turn <b>left</b> onto the <b>Don Valley Parkway</b> ramp Merge onto <b>Don Valley Pkwy N</b>
Take the <b>ON-401 E</b> exit Merge onto <b>Ontario 401 Express</b>
Merge onto <b>ON-401 E</b>
Keep <b>left</b> at the fork to continue on <b>ON-401</b>
Continue onto <b>Autoroute du Souvenir/Autoroute 20</b>
<div style="font-size:0.9em">Entering Québec</div>
Keep <b>left</b> to continue on <b>Boulevard Ville-Marie/Autoroute 720 E</b>
Keep <b>right</b> to stay on <b>Boulevard Ville-Marie/Autoroute 720 E</b>
Take exit <b>4</b> toward <b>Rue de la Montagne N/Rue Saint-Jacques</b>
Turn <b>left</b> onto <b>Jean d'Estrees St</b>
Turn <b>right</b> onto <b>St Antoine St W</b>
Turn <b>left</b> onto <b>Rue Mansfield</b>
Turn <b>right</b> onto <b>René-Lévesque Blvd W</b>
Turn <b>right</b> onto <b>Boulevard Robert-Bourassa</b>
<div style="font-size:0.9em">Destination will be on the right</div>

你的代码只能从多伦多到蒙特利尔使用。我有地址A的输入和地址B的输入,我需要从A到B的方向。你知道如何在代码中自定义来源和目的地吗?@TheAndruino:代码只是一个例子。你应该根据需要修改它。请阅读答案中的链接文档。如何将纬度和经度转换为placeID?