非百度坐标系转换:用户可通过该服务,实现非百度坐标系(GPS标准坐标、amap地图坐标、tencent地图坐标、mapbar地图坐标等)到百度坐标系的转换。
- 单次请求可批量解析100个坐标
读取经纬度(wgs84)
import requests import json import time def get_urls(add): url = "https://api.map.baidu.com/geoconv/v1/?coords=" + str(add) url = url + "&from=1&to=5&ak=11Z8uiP8kIz6AG0Vjiwzbc***" r = requests.get(url) res = json.loads(r.text) # 数据格式化; content = str(res['result'][0]['x']) + "," + str(res['result'][0]['y']) + "\n" # 写入文件 with open('data.txt', 'a') as f: f.write(content) return ""
依次输出转化后的经纬度
# 地址信息; with open(r'add.txt', 'r', encoding='utf-8') as f: # 读取地址信息列表 address = f.read().split() # 地址转换 i = 0 for item in address: # 调用百度转换API封装函数; get_urls(item) print("第{}个地址已转换".format(i + 1)) i += 1
单次请求可批量解析100个坐标
if i % 99 == 0 and i > 0: print("第", i, "个数据,执行延迟策略.") time.sleep(1)
lockdatav Done!