调用谷歌地图api接口实现地图显示
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*"errorPage="" %>
/*function loadXMLDoc(){
varxmlhttp;
if(window.XMLHttpRequest){
xmlhttp=newXMLHttpRequest();
}else{
xmlhttp=newActiveXObject("Microsoft.XMLHTTP");
}
returnxmlhttp;
}*/
/*function loadXMLDoc(){
varxmlhttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}*/
function loadXMLDoc() {
//针对FireFox,Mozillar,Opera,Safari,IE7,IE8
//alert(window.XMLHttpRequest);
if(window.XMLHttpRequest)
return new XMLHttpRequest();
//针对IE5,IE5.5,IE6
else if (window.ActiveXObject){
//两个可以用于创建XMLHTTPRequest对象的控件名称,保存在一个JS数组中。
var activexName =["MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
for(var i = 0; i //取出一个控件名进行创建,如果成功就终止循环 try{ return new ActiveXObject(activexName[i]); break; }catch(e){ return null; } } } } //XMLDcoument加载方法 function createXMLDoc(respon){ varxmldoc=null; try{ xmldoc=newActiveXObject("Microsoft.XMLDOM"); xmldoc.async=false; //同步 xmldoc.loadXML(respon); }catch(e){ try{ varparser=new DOMParser(); xmldoc=parser.parseFromString(respon,"text/xml"); }catch(e){} } returnxmldoc; } function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_wlan")); map.setCenter(new GLatLng(39.9081726, 116.3979471),4); map.enableScrollWheelZoom(); //map.addControl(newGLargeMapControl()); //map.addControl(newGMapTypeControl()); map.setUIToDefault(); varicon = new GIcon(); icon.image ="http://labs.google.com/ridefinder/images/mm_20_green.png"; icon.shadow ="http://labs.google.com/ridefinder/images/mm_20_shadow.png"; icon.iconSize = new GSize(15, 30); icon.shadowSize = new GSize(30, 30); icon.iconAnchor = new GPoint(6, 20); icon.infoWindowAnchor = new GPoint(5, 10); varframe=parent.frames.topFrame; varcity=frame.document.getElementById("city").value; varlat=frame.document.getElementById("lat").value; varlng=frame.document.getElementById("lng").value; varhotlat=frame.document.getElementById("hotlat").value; varhotlng=frame.document.getElementById("hotlng").value; vargrade=frame.document.getElementById("grade").value; varhotid=frame.document.getElementById("hotid").value; varparentid=frame.document.getElementById("parentid").value; vartypename=frame.document.getElementById("typename").value; varjudge=frame.document.getElementById("judge").value; varhotname=frame.document.getElementById("hotname").value; varhotaddress=frame.document.getElementById("hotaddress").value varareaCenter; if(lat!=null&&lat!="null"&&lat!=""&&grade=="2"&&judge!="judge"){ areaCenter=newGLatLng(parseFloat(lat),parseFloat(lng)); map.setCenter(areaCenter,7); }elseif(lat!=null&&lat!="null"&&lat!=""&&grade=="3"&&judge!="judge"){ areaCenter=newGLatLng(parseFloat(lat),parseFloat(lng)); map.setCenter(areaCenter,11); }elseif(lat!=null&&lat!="null"&&lat!=""&&grade=="4"&&judge!="judge"){ areaCenter=newGLatLng(parseFloat(lat),parseFloat(lng)); map.setCenter(areaCenter,13); }elseif(hotlat!=null&&hotlat!="null"&&hotlat!=""&&hotid!=null&&hotid!="null"&&hotid!=""){ areaCenter=newGLatLng(parseFloat(hotlat),parseFloat(hotlng)); map.setCenter(areaCenter,17); } varcenterMarker = new GMarker(areaCenter,icon); if(hotid!=null&&hotid!="null"&&hotid!=""){ map.addOverlay(centerMarker); createMarker(centerMarker,hotid); //map.addOverlay(createMarker(centerMarker,hotid)); typename=""; hotname=""; hotaddress=""; frame.document.getElementById("hotid").value=""; frame.document.getElementById("judge").value=""; } varloadXml=loadXMLDoc(); varurl="hotlist.jsp?parentid="+parentid+"&grade="+grade; if(typename!=null&&typename!=""){ url+="&typename="+typename; } if(hotname!=null&&hotname!=""){ url+="&hotname="+hotname; } if(hotaddress!=null&&hotaddress!=""){ url+="&hotaddress="+hotaddress; } loadXml.open("GET",url,false); loadXml.onreadystatechange=function(){ if(loadXml.readyState==4&&loadXml.status==200){ varxmldoc=createXMLDoc(loadXml.responseText); varhotlists=xmldoc.getElementsByTagName("hotlist"); if(parseInt(grade)>2){ if(hotlists.length>0){ for(vari=0;i //alert(hotlists[i].getAttribute("hotname")); varhotCenter=newGLatLng(parseFloat(hotlists[i].getAttribute("lat")),parseFloat(hotlists[i].getAttribute("lng"))); var marker=new GMarker(hotCenter,icon) map.addOverlay(createMarker(marker,hotlists[i].getAttribute("id"))); //map.addOverlay(marker); } if(typename!=null&&typename!=""){ map.setCenter(hotCenter,12); } if(hotname!=null&&hotname!=""){ map.setCenter(hotCenter,12); } if(hotaddress!=null&&hotaddress!=""){ map.setCenter(hotCenter,12); } } } } }; //searchHotCount(); loadXml.send(null); } } function createMarker(marker,id){ GEvent.addListener(marker,"click",function(){ setSpecValue(marker,id); }); returnmarker; } function setSpecValue(marker,id){ varframe=parent.frames.topFrame; varparentid=frame.document.getElementById("parentid").value; vargrade=frame.document.getElementById("grade").value; varloadXml=loadXMLDoc(); varurl="hotlist.jsp?parentid="+parentid+"&grade="+grade; if(id!=null&&id!=""){ url+="&id="+id; } loadXml.open("GET",url,false); loadXml.onreadystatechange=function(){ if(loadXml.readyState==4&&loadXml.status==200){ varxmldoc=createXMLDoc(loadXml.responseText); varhotvalue=xmldoc.getElementsByTagName("hotlist"); marker.openInfoWindowHtml( "热点id:"+hotvalue[0].getAttribute("id")+""+ "热点名称:"+hotvalue[0].getAttribute("hotname")+""+ "热点地址:"+hotvalue[0].getAttribute("address")+""+ "热点类型:"+hotvalue[0].getAttribute("type")+""+ "覆盖范围:"+hotvalue[0].getAttribute("area")+""+ //"经度:"+hotvalue[0].getAttribute("lat")+""+ //"纬度:"+hotvalue[0].getAttribute("lng")+""+ "" ); } }; loadXml.send(null); varhotid=frame.document.getElementById("hotid").value=""; } function hotexport(obj){ varframe=parent.frames.topFrame; varcity=frame.document.getElementById("city").value; vargrade=frame.document.getElementById("grade").value; if(city==""){ alert("请先选择城市再导出!"); returnfalse; } if(city!=""){ obj.href="excelExport.jsp?city="+city+"&grade="+grade; } } function searchHotCount(){ varframe=parent.frames.topFrame(); vartotalCount=frame.document.getElementById("totalCount").value; varsearchHotCount=document.getElementById("searchHotCount"); if(totalCount!=""){ searchHotCount.innerHTML="当前共为您找到"+totalCount+"个符合条件的wlan热点信息!"; } }