- web前端展示1:
-
文本标注 - web前端展示2:
-
给多个点添加信息窗口 点击标注点,可查看由纯文本构成的简单型信息窗口
服务器端,采用cgi方式,数据json格式数据放到apache的cgi目录:
/var/www/html/cgin-bin/oalogin_read.cgi
httpd.conf配置文件增加选项:AddHandler cgi-script .cgi
更改权限:
chown apache.apache oalogin_read.cgi
chmod u+x oalogin.read.cgi
#!/usr/bin/env python# -*- coding: utf-8 -*-import pickleimport urllibimport urllib2import json## 根据ip地址从百度地图api返回位置,地址等信息def getInfoByIP(ip): ak="shmFW60npXiuwVtfXAUNS9AR" url="http://api.map.baidu.com/location/ip?ak="+ak+"&ip="+ip+"&coor=bd09ll" #为urllib2 设置代理 proxy=urllib2.ProxyHandler({'http': 'http://10.10.61.4:3128'}) opener= urllib2.build_opener(proxy) urllib2.install_opener(opener) req = urllib2.Request(url) res_data = urllib2.urlopen(req) res = res_data.read() json_data = json.loads(res) item={} if json_data.has_key('address') and json_data.has_key('content'): # print json_data['address'].encode('utf-8').decode('utf-8'),json_data['content']['point'] item['address']=json_data['address'] item['point']=json_data['content']['point'] return item输出json格式数据def jsonResponse(result_json): import cgi import cgitb cgitb.enable() print "Content-type:application/json" print #cgi.print_environ() print result_jsonif __name__ == "__main__": #从login.pk 文件中读取ip地址信息 login_db = open('/var/www/cgi-bin/login.pk','r') login_data = pickle.load(login_db) login_ips={} for item in login_data: # print item[0].decode('utf8'),item[1:] ip = item[-1].strip() if login_ips.has_key(ip): login_ips[ip]+=1 else: login_ips[ip]=1 #print login_ips #循环获取ip地址的详细信息 map_data_json=[] for ip in login_ips.keys(): ip_data = getInfoByIP(ip) map_data_json.append(ip_data) encodejson=json.dumps(map_data_json) jsonResponse(encodejson)
- 参考文档: