非百度坐标系转换:用户可通过该服务,实现非百度坐标系(GPS标准坐标、amap地图坐标、tencent地图坐标、mapbar地图坐标等)到百度坐标系的转换。
读取经纬度(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:
get_urls(item)
print("第{}个地址已转换".format(i + 1))
i += 1
单次请求可批量解析100个坐标
if i % 99 == 0 and i > 0:
print("第", i, "个数据,执行延迟策略.")
time.sleep(1)
lockdatav Done!
|