import pandas as pd
import requests
import jsondef get_dis_tm(origin, destination,city,cityd):url = 'https://restapi.amap.com/v3/direction/transit/integrated?'key = 'xxx' #这里就是需要去高德开放平台去申请key,请在xxxx位置填写,web服务APIlink = '{}origin={}&destination={}&city={}&cityd={}&strategy=0&key={}'.format(url, origin ,destination ,city, cityd,key)response = requests.get(link)dis, tm = 999999, 999999if response.status_code == 200:results = response.json()print(results)if results['status'] == '1':cost = results['route']['transits'][0]['cost'] # 有多条方案,我就直接选方案0了duration = results['route']['transits'][0]['duration']dis =results['route']['transits'][0]['distance']else:print(link)return results,dis,duration,costo= '116.481028,39.989643' # 起点坐标
d= '116.434446,39.90816' #终点坐标
city = '北京' #起始城市 ,支持市内公交换乘/跨城公交的起点城市,规则:城市名称/citycode
cityd = '北京' #终止城市,跨城公交规划必填参数。规则:城市名称/citycode
results,dis,duration,cost= get_dis_tm(o,d,city,cityd)
dis,duration,cost