带分页功能的周边晚点搜索

最近在看Goole 地图,现在贴一个例子。

代码:

<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" type="text/css" href="style.css"></link>
  <script
   src="http://ditu.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA&hl=zh-CN"
   type="text/javascript"></script>
  <style type="text/css">
    @import url("http://www.google.com/uds/css/gsearch.css");
    @import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css");
   #top ul li{
   float:left;
   padding:3px 8px;
  
   }
   #top {
   width:100%;
   border-bottom:1px #666 solid;
   clear:both;
   height:20px;
   }
        #addHotelMap {
          border : 1px solid #979797;
          width :79%;
          height : 500px;
          float:left;
        }
         #searchResult {
          border : 1px solid #979797;
          width : 45%;
          height : 570px;
          float:left;
             overflow-y:scroll;
             padding:5px;
        }
     #searchResult div{
          padding:5px 0;
    color:#333;
        }
        ul,li{
    margin:0;
    padding:0;
    list-style:none;
     }
     body{
     color:#999;
     font-size:12px;
     height:98%;
     }
     h1{
   color:#666;
     padding:0;
     margin:0;
     font-size:14px;
     line-height:22px;
     height:22px;
     }
       #schollContainer div.list{
           background:url("scholl.png") no-repeat left;
           padding-left:20px;
       }
  </style>

  <script type="text/javascript">
          var cenx = 23.139531;
          var ceny = 113.331259;
          var stzoom = 13;
          var map;
          var curr = 2;
          var markers = [];
         
         function Getgeo(current_page){
           
            if(current_page < 0)
              curr = curr + current_page+1;
            else if(current_page > 0)
              curr = curr + current_page;        
           
            var search_value = document.getElementById('search_address').value;
            var search_center = document.getElementById('search_center').value;
            if (search_center && search_value) {
                var request = GXmlHttp.create();

                if (current_page == 0)
                    request.open("GET", "http://ditu.google.cn/maps?output=kml&hl=zh-CN&q=" + search_value + "&near=" + search_center + "&start=0", true);
                else
                    request.open("GET", "http://ditu.google.cn/maps?output=kml&hl=zh-CN&q=" + search_value + "&near=" + search_center + "&start=" + ((curr) * 10), true);

                request.onreadystatechange = function() {
                    if (request.readyState == 4) {

                        onTypeData(request.responseText);
                    }
                }
                request.send(null);
            }
     
         }
        
         window.selectMarker = function(i){
       GEvent.trigger(markers[i], 'click');
      }

      window.onTypeData = function(data) {

          var xml = GXml.parse(data);
          var result = "";
          var placemarks = xml.documentElement.getElementsByTagName("Placemark");
          markers = [];
          map.clearOverlays();

          for (var i = 0; i < placemarks.length; i++) {
              var placemark_objs = placemarks[i].childNodes;
              var placemark_styles = placemark_objs[3].childNodes;
              var text = placemark_styles[1].childNodes[1];
              var point = new GLatLng(placemark_objs[4].nodeTypedValue.split(",")[1], placemark_objs[4].nodeTypedValue.split(",")[0]);

              var icon = new GIcon();
              icon.iconSize = new GSize(36, 51);
              //icon.image = "images/schools.png";
              // icon.image = "http://maps.google.com/mapfiles/kml/shapes/schools.png";
              icon.iconAnchor = new GPoint(18, 51);
              icon.infoWindowAnchor = new GPoint(10, 6);

              var marker = new GMarker(point, {
                  icon: icon,
                  title: placemark_objs[0].nodeTypedValue
              });
              marker.point = point;
              marker.text = text;
            
              map.addOverlay(marker);
              markers.push(marker);

              GEvent.addListener(marker, "click", GEvent.callbackArgs(this, openInfoWindow, marker));

              result = result + "<br> " +
                "<a href=/"javascript:selectMarker(" + i + ")/">" +
                "名称:" + placemark_objs[0].nodeTypedValue +
                "; 地址:" + placemark_objs[2].nodeTypedValue +
                "; 坐标:" + placemark_objs[4].nodeTypedValue + "</a>" +
              "<br>";
          }

          result = result + "<a href=/"javascript:Getgeo(-2)/">" + (curr - 1) + "</a> , " +
            "<a href=/"javascript:Getgeo(-1)/">" + curr + "</a> , " +
            "<a href=/"javascript:Getgeo(1)/">" + (curr + 1) + "</a> , " +
            "<a href=/"javascript:Getgeo(2)/">" + (curr + 2) + "</a>";

          document.getElementById('schollContainer').innerHTML = result;
      }
        
        function openInfoWindow(marker){         
           var tabs = [];
           var imgHtml = "<div style='width:400px;font-size:13px;'>" + marker.text.nodeTypedValue + "</div>";
           if (imgHtml.indexOf("$[geDirections]") > 0) {
               imgHtml = imgHtml.substring(0, imgHtml.indexOf("$[geDirections]"))+"</div>"
           }
          imgHtml= imgHtml.replace("$[name]",marker.NA.title)
           var infoHtml = "<div style='width:400px;font-size:13px;'>"+marker.NA.title+"</div>";
       
           tabs.push(new GInfoWindowTab("信息", infoHtml));
           tabs.push(new GInfoWindowTab("图片", imgHtml));          
           marker.openInfoWindowTabsHtml(tabs);
   } 

         function init(){
          //检查浏览器的兼容性.
             if (GBrowserIsCompatible()){
              //debugger;
                 map=new GMap2(document.getElementById("map_canvas"));
     
     //设置地图的中心坐标.
                 var loc = new GLatLng(cenx,ceny);
                 map.setCenter(loc,stzoom);
                
                 //创建带有可在四个方向平移、放大、缩小的按钮,以及缩放滑块的控件。
     map.addControl(new GLargeMapControl());
     
     //创建带有切换地图类型的按钮的控件。
     map.addControl(new GMapTypeControl());       
     
             }
         }       
       
         //初始化地图
         window.οnlοad=init;
        
         //卸载地图
         window.οnunlοad=GUnload;      
   
    </script>

 </head>
 <body>
  <!-- 地图画板 -->
  搜索内容: <input type="text" name="search_address" id="search_address" />
  搜索中心: <input type="text" name="search_center" id="search_center" />
  <input type="button" value="搜索" οnclick="Getgeo(0)" /> 
  <div id="searchResult">
                搜索结果:<div id="schollContainer"></div>
        </div>
       
        <div id="map_canvas" style="width:54%; height:570px ;float:left;"></div>
 </body>
</html>
运行结果:

 

这个只是打开的html,在部署到IIS报没有权限

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值