赞
踩
1、提前获取全国市县坐标形成excel表格,可反复使用 2、定位出发地坐标 3、利用高德标准货车接口进行里程计算 4、利用高德返回的json,python对json、excel进行操作
- import requests
- import json
- import xlwings as xw
-
- def get_dis(destination):
- origin = '120.936848,31.897215' #出发地坐标,也可写为变量待传
- url = 'https://restapi.amap.com/v4/direction/truck?parameters' # 货车路径
- key = '自己申请的高德key,但有限额,需购买' #需要填写
- link = f'{url}&origin={origin}&destination={destination}&key={key}&size={4}&height={1.6}' \
- f'&width={2.5}&load={49}&weight={31}&axis={6}'
- # size 车辆4 重型车;height车辆高度1.6;width车辆宽度2.5;load车辆总重49;weight车辆核定载重31;axis车轴数量6;
- response = requests.get(link)
- data = response.json()
- distance = data['data']['route']['paths'][0]['distance'] # 获取里程值
- return distance
-
-
- app = xw.App(visible=False, add_book=False)
- filepath = r'D:\pytest\newinta.xlsx' # 全国城市坐标(精细至区县)
- workbook = app.books.open(filepath) # 打开坐标表
- worksheet = workbook.sheets["Sheet1"] # 打开坐标页
- # for i in range(2,3507) #全国约3507个县(区):
- for i in range(2, 10):
- data = worksheet.range(f"E{i}:F{i}").value # 重点坐标获取,也可在excel表中先合并
- data1 = ','.join(str(j) for j in data) # []列表转化为元素
- print(get_dis(data1))
- worksheet.range(f"L{i}").value = get_dis(data1)
- workbook.save(r'D:\pytest\newinta6.xlsx')
- workbook.close()
- app.quit()
受限于高德地图对货车里程的限制,每日仅可调用接口100次,新手菜鸟希望高手指点,如何优化。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。