调用谷歌地图api接口实现地图显示

调用谷歌地图api接口实现地图显示

<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*"errorPage="" %>

<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<metahttp-equiv="Content-Type" content="text/html;charset=gb2312" />

<metahttp-equiv="X-UA-Compatible" content="IE=EmulateIE7"/> 

<META HTTP-EQUIV="Pragma"CONTENT="no-cache" >

<METAHTTP-EQUIV="Cache-Control" CONTENT="no-cache" >

<meta http-equiv="expires"content="0" > 

<title>热点地图显示页面</title>

 

<script charset="utf-8"type="text/javascript"src='http://ditu.google.cn/maps?file=api&amp;v=2&amp;key=ABQIAAAA8isncdaDTmdPzP31-PpKtBRjqOEOdO7Uti1UxHh75vPMkzVFhhTF63QjSTUWM9vWVd3bm0e2vIqGmg'></script>

 

<scripttype="text/javascript">

 

/*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<activexName.length; 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<hotlists.length;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(

                            "<b>热点id:"+hotvalue[0].getAttribute("id")+"</br>"+

                            "<b>热点名称:"+hotvalue[0].getAttribute("hotname")+"</br>"+

                            "<b>热点地址:"+hotvalue[0].getAttribute("address")+"</br>"+

                            "<b>热点类型:"+hotvalue[0].getAttribute("type")+"</br>"+

                            "<b>覆盖范围:"+hotvalue[0].getAttribute("area")+"</br>"+

                            //"<b>经度:"+hotvalue[0].getAttribute("lat")+"</br>"+

                            //"<b>纬度:"+hotvalue[0].getAttribute("lng")+"</br>"+

                            "<b>"

                     );

              }

       };

       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热点信息!";

       }

      

}

 

</script>

</head>

 

<bodyοnlοad="initialize();onMapLoad();" οnunlοad="GUnload()"style="height:100%">

<table width="100%"border="0" cellspacing="0" cellpadding="0">

 <tr>

   <td>

         <table width="100%" border="0"cellspacing="0" cellpadding="0">

           <tr>

                <td width="220px"align="left">

                </td>

                <td width="500px"align="center">

                </td>

                <td id="searchHotCount"width="150px" align="center">

                </td>

                <td width="85px"align="right">

                  <a href="#"id="hotexport" οnclick="hotexport(this)">热点导出</a>

                </td>

              </tr>

         </table>

       </td>

 </tr>

 <tr>

 <div id="map_wlan" style="width: 100%; height:400px"></div>

 </tr>

</table>

 

</body>

</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值