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

python 复制代码
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


相关推荐
2301_810160951 分钟前
使用Pandas进行数据分析:从数据清洗到可视化
jvm·数据库·python
福运常在15 分钟前
股票数据API(21)如何获取股票指数最新分时交易数据
java·python·maven
H1_Coldfire19 分钟前
Nanbeige4.1-3B本地化部署(GPU RTX 3090)
python·语言模型
Bert.Cai24 分钟前
Python逻辑运算符详解
开发语言·python
AC赳赳老秦29 分钟前
OpenClaw SEO写手Agent实操:生成结构化文章,适配CSDN搜索规则
大数据·人工智能·python·搜索引擎·去中心化·deepseek·openclaw
廖圣平37 分钟前
从零开始,福袋直播间脚本研究【八】《策略模式》
开发语言·python·bash·策略模式
2301_8042154140 分钟前
Python类型提示(Type Hints)详解
jvm·数据库·python
第一程序员1 小时前
非专业转码心路历程与Rust学习规划
python·github
一帧一画1 小时前
基于 CNN+LSTM 的全国年度降水预测实践
python·cnn·lstm
骄阳似火_20181 小时前
Anaconda的详细安装步骤
python