高德地图_公共交通路径规划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


相关推荐
Full Stack Developme1 分钟前
spring #{} 与 ${} 区别
windows·python·spring
马腾化云东3 分钟前
Agent开发应知应会(Langfuse):Langfuse Session概念详解和实战应用
人工智能·python·llm
松涛和鸣11 分钟前
75、 IMX6ULL LM75温度传感器I2C驱动开发
java·linux·数据库·驱动开发·python
甄心爱学习12 分钟前
【python】list的底层实现
开发语言·python
edisao32 分钟前
第三章 合规的自愿
jvm·数据仓库·python·神经网络·决策树·编辑器·动态规划
cuber膜拜43 分钟前
Tenacity 原理与基本使用
服务器·网络·python·装饰器模式·tenacity
Myosotis51343 分钟前
作业 第三次
开发语言·python
cuber膜拜44 分钟前
PyBreaker 原理与基本使用
服务器·网络·python·pybreaker
学Linux的语莫1 小时前
模型转为RKNN格式
python·深度学习·机器学习
Albert Edison1 小时前
【Python】文件
android·服务器·python