1. IP转经纬度
- 工具:GeoIP python
- 每个IP一行
- 代码:
import GeoIP
import sys
import os
def print_usage():
print "Usage: " + os.path.basename(__file__) + " ipfile.txt"
# make sure we've been passed the filename containing IP addresses
if len(sys.argv) != 2:
print_usage()
sys.exit()
# grab the filename
ipfile = sys.argv[1];
# initialize the GeoIP database
gi = GeoIP.open("GeoLiteCity.dat",GeoIP.GEOIP_STANDARD)
# for each IP in the file...
for line in open(ipfile, "r"):
# strip newlines
ip = line.rstrip()
# look up GeoIP record for this IP
gir = gi.record_by_name(ip)
# print lat/long if found in db
if gir != None:
print '{"lng":'+str(gir['longitude'])+',"lat":'+str(gir['latitude'])+',"count":1},'
- 运行
python geolite.py ipfile.txt > ip_res.txt
2. 用ip_res.txt的结果替换百度地图API内的经纬度信息
- 百度地图热力图API:http://lbsyun.baidu.com/jsdemo.htm#c1_15
- 需要注意:使用前需要获得AK