网格距离计算

复制代码
def get_dis_tm(origin, destination):
    url = 'https://restapi.amap.com/v3/direction/driving?'
    key = '208ce530fdd2dc162c8831657fff3232' #这里就是需要去高德开放平台去申请key,请在xxxx位置填写
    link = '{}origin={}&destination={}&key={}&strategy={}'.format(url, origin ,destination , key,"2")
    response = requests.get(link)
    dis, tm = 999999, 999999
    if response.status_code == 200:
        results = response.json()
        if results['status'] == '1':
            for temp in results['route']['paths']:
                print(temp['distance'])

        if results['status'] == '1':
            dis = int(results['route']['paths'][0]['distance'])
            tm = int(results['route']['paths'][0]['duration'])
        else:
            print(link)
    response.close()
    return dis, tm
复制代码

 

posted @   子过杨梅  阅读(65)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示