本文主要是介绍高德地图_公共交通路径规划API,获取两地点之间的驾车里程和时间,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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
这篇关于高德地图_公共交通路径规划API,获取两地点之间的驾车里程和时间的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!