调用百度地图api呈现热力图
数据来源,wordpress博客的访问,百度网盘https://pan.baidu.com/s/1slqbCZF 提取码 dv6f
ip采集插件:SlimStat;
使用百度ip定位api将ip转化为经纬度坐标,也写成json文件,
import urllib
import time
IpList = open("ip_add_all.json","r").read()
Ip = eval(IpList)
flag = 0
file = open('point.json’,’a’)
for i in range(len(Ip)):
ip = Ip[i]['ip']
res = urllib.request.urlopen("http://api.map.baidu.com/location/ip?ak=KrmZxHHwvLnl4Xfyt0FMMVzgGLaaxU2j&ip="+ip+"&coor=bd09ll")
a = res.read()
zidian = eval(a)
flag += 1
if(zidian['status'] == 0):
print(flag,ip)
lng = zidian['content']['point']['x']
lat = zidian['content']['point']['y']
str_temp = '{"lat": '+lat+', "lng":'+lng+'},\n'
file.write(str_temp)
file.close()
另外我也将得到的.json文件转化为了.csv文件,都在百度云上
修改里面的point数组,则可以将之前采集的点呈现上去,
http://developer.baidu.com/map/jsdemo.htm#c1_15 百度地图开放平台
import pandas as pd
data = pd.read_csv('points.cv')
for i in range(len(data)):
print('{' + '\"lng\":' + str(data.iloc[i][2])[:-2] +',\"lat\":' + str(data.iloc[i][1])[:-2] + ',\"count\":' + str(int(data.iloc[i][3])) + '}') # 将数据转化成需要的格式