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


相关推荐
AI探索者14 小时前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者14 小时前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh16 小时前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅16 小时前
Python函数入门详解(定义+调用+参数)
python
曲幽17 小时前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama
两万五千个小时21 小时前
落地实现 Anthropic Multi-Agent Research System
人工智能·python·架构
哈里谢顿1 天前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)
python
用户8356290780512 天前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng82 天前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi2 天前
Chapter 2 - Python中的变量和简单的数据类型
python