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