资源简介
将地名信息解析为百度坐标,获得经纬度,坐标系为BD09.
输入包含地址名称的TXT文档,输出为百度坐标文档~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
代码片段和文件信息
# -*- coding: utf-8 -*-
import sys urllib urllib2 json
city = ‘南京‘
f = open(‘input.txt‘‘r‘)
lines = f.readlines()
f.close()
adds = []
for line in lines:
temp1 = line.strip(‘\n‘)
adds.append(temp1)
print len(adds)
f1 = open(‘output.txt‘‘w‘)
f1.write(‘‘)
f1.close()
f2 = open(‘output.txt‘‘a‘)
f2.write(str(len(adds)))
f2.write(‘\n‘)
i = 0
while i < len(adds):
u = adds[i]
url = “http://api.map.baidu.com/geocoder/v2/?&city=“ + city + “&output=json&ak=tvPqvSAc1KwVipptgYLuuFnW&address=“ + u
req = urllib2.Request(url)
resp = urllib2.urlopen(req)
content = resp.read()
if(content):
t = json.loads(content)
lng = -1
lat = -1
if t[“status“] == 0:
lng = t[“result“][“location“][“lng“]
lat = t[“r
评论
共有 条评论