需要安装第三方包:requests
本次经纬度匹配采用高德地图api,首先将gps坐标转化为高德地图的经纬度坐标,然后再根据转化后的坐标进行匹配。
本次匹配主要是获取距离给定经纬度最近的poi点地址信息。
主要程序如下所示:
1 #-*-coding:utf8-*- 2 import requests 3 import csv 4 import chardet 5 import sys 6 reload(sys) 7 sys.setdefaultencoding("utf8") 8 9 location='116.81963,40.310799' 10 def geocode(location): 11 parameters={'location':location,'key':'7447d3ae24afa6497f1b459fc5cd0419','extensions':'all'} 12 base = 'http://restapi.amap.com/v3/geocode/regeo' 13 response = requests.get(base,parameters) 14 answer = response.json() 15 print answer['regeocode']['pois'][0]['name'] 16 17 def transform(location): 18 parameters = {'locations':location,'coordsys':'gps','key':'7447d3ae24afa6497f1b459fc5cd0419'} 19 base = 'http://restapi.amap.com/v3/assistant/coordinate/convert' 20 response = requests.get(base,parameters) 21 answer = response.json() 22 return answer['locations'] 23 24 25 geocode(transform(location))
运行结果如下图所示:
如果需要获取其他地址信息可输出对应的answer中的其他值,值的名称对应如下图所示: