高德地图_公共交通路径规划API,获取两地点之间的驾车里程和时间

2023-12-25 18:51:10
import pandas as pd
import requests
import json

def get_dis_tm(origin, destination,city,cityd):
    url = 'https://restapi.amap.com/v3/direction/transit/integrated?'
    key = 'xxx' #这里就是需要去高德开放平台去申请key,请在xxxx位置填写,web服务API
    link = '{}origin={}&destination={}&city={}&cityd={}&strategy=0&key={}'.format(url, origin ,destination ,city, cityd,key)
    response = requests.get(link)
    dis, tm = 999999, 999999
    if 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,cost



o= '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

在这里插入图片描述
在这里插入图片描述

文章来源:https://blog.csdn.net/sheyueyu/article/details/135205860
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。