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


相关推荐
CaracalTiger2 小时前
什么是Clawdbot?Clawdbot下载、安装、配置教程(最新版Moltbot)
python·编辑器·aigc·idea·ai编程·intellij idea·agi
WJX_KOI7 小时前
Open Notebook 一个开源的结合AI的记笔记软件
python
0思必得07 小时前
[Web自动化] 反爬虫
前端·爬虫·python·selenium·自动化
2301_822382768 小时前
Python上下文管理器(with语句)的原理与实践
jvm·数据库·python
喵手8 小时前
Python爬虫实战:从零搭建字体库爬虫 - requests+lxml 实战采集字体网字体信息数据(附 CSV 导出)!
爬虫·python·爬虫实战·零基础python爬虫教学·csv导出·采集字体库数据·字体库字体信息采集
2301_790300969 小时前
Python深度学习入门:TensorFlow 2.0/Keras实战
jvm·数据库·python
程序员敲代码吗10 小时前
用Python生成艺术:分形与算法绘图
jvm·数据库·python
Yyyyy123jsjs10 小时前
如何通过免费的外汇API轻松获取实时汇率数据
开发语言·python
喵手10 小时前
Python爬虫实战:GovDataMiner —— 开放数据门户数据集元数据采集器(附 CSV 导出)!
爬虫·python·爬虫实战·python爬虫工程化实战·零基础python爬虫教学·open data·开放数据门户数据集列表