posts - 310, comments - 6939, trackbacks - 0, articles - 3
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          http://www.playgoogle.com/post/44.html 
          將GOOGLE MAP API 和 GOOGLE Search API 進(jìn)行整合,我用面向?qū)ο蟮姆绞綄懥艘粋€類,通過傳一個經(jīng)緯度進(jìn)去,自動通過GOOGLE LOCAL SEARCH獲取附近的相關(guān)信息。比如餐廳、景點(diǎn)等,反過來標(biāo)到地圖上,并可在任意容器內(nèi)顯示。

          下面是源碼:

          /*
          *Author:karry
          *Version:1.0
          *Time:2008-12-01
          *KMapSearch 類
          *把GOOGLE MAP 和LocalSearch結(jié)合。只需要傳入MAP\經(jīng)緯度值,就可以把該經(jīng)緯度附近的相關(guān)本地搜索內(nèi)容取出來,在地圖上標(biāo)注出來,并可以在指定容器顯示搜索結(jié)果
          */


          (
          function() {
              
          var markers= new Array(); 
              
          var KMapSearch=window.KMapSearch= function(map_, opts_) {
                  
          this.opts = {
                      container:opts_.container 
          || "divSearchResult",
                      keyWord:opts_.keyWord 
          || "餐廳",
                      latlng: opts_.latlng 
          || new GLatLng(31121),
                      autoClear:opts_.autoClear 
          || true,
                      icon:opts_.icon 
          || new GIcon(G_DEFAULT_ICON)
                  }
          ;
                  
          this.map = map_;
                  
          this.gLocalSearch = new google.search.LocalSearch();
                  
          this.gLocalSearch.setCenterPoint(this.opts.latlng);
                  
          this.gLocalSearch.setResultSetSize(GSearch.LARGE_RESULTSET);
                  
          this.gLocalSearch.setSearchCompleteCallback(thisfunction() {
                      
          if (this.gLocalSearch.results) {
                          
          var savedResults = document.getElementById(this.opts.container);
                          
          if (this.opts.autoClear) {
                              savedResults.innerHTML 
          = "";
                          }

                          
          for (var i = 0; i < this.gLocalSearch.results.length; i++{
                              savedResults.appendChild(
          this.getResult(this.gLocalSearch.results[i]));
                          }

                      }

                  }
          );
              }

              KMapSearch.prototype.getResult 
          = function(result) {
                  
          var container = document.createElement("div");
                  container.className 
          = "list";
                  
          var myRadom =(new Date()).getTime().toString()+Math.floor(Math.random()*10000);
                  container.id
          =myRadom;
                  container.innerHTML 
          = result.title + "<br />地址:" + result.streetAddress;
                  
          this.createMarker(new GLatLng(result.lat, result.lng), result.html,myRadom);
                  
          return container;
              }

              KMapSearch.prototype.createMarker 
          = function(latLng, content)
              
          {
                  
          var marker = new GMarker(latLng, {icon:this.opts.icon,title:this.opts.title});
                  GEvent.addListener(marker, 
          "click"function() {
                      marker.openInfoWindowHtml(content);
                  }
          );
                  markers.push(marker);
                  map.addOverlay(marker);
              }

              KMapSearch.prototype.clearAll 
          = function() {
                  
          for (var i = 0; i < markers.length; i++{
                      
          this.map.removeOverlay(markers[i]);
                  }

                  markers.length 
          = 0;
              }

              KMapSearch.prototype.execute 
          = function(latLng) {
                  
          if (latLng) {
                      
          this.gLocalSearch.setCenterPoint(latLng);
                  }

                  
          this.gLocalSearch.execute(this.opts.keyWord);
              }

          }
          )();


          使用方法:

           var myIcon = new GIcon(G_DEFAULT_ICON);
                      myIcon.image 
          = "canting.png";
                      myIcon.iconSize 
          = new GSize(1620);
                      myIcon.iconAnchor 
          = new GPoint(820);
                      myIcon.shadow 
          = "";
                      
          var mapSearch = new KMapSearch(map, {container:"cantingContainer",latlng:initPt,icon:myIcon,keyWord:"餐廳"});
                      mapSearch.clearAll();
                      mapSearch.execute();

           

           點(diǎn)擊這里查看演示示例:經(jīng)緯度查詢整合本地搜索


          評論

          # re: Google Map Api和GOOGLE Search Api整合擴(kuò)展地圖本地搜索  回復(fù)  更多評論   

          2009-06-25 22:31 by Guoxin
          你好,你知道在window桌面怎樣用Google Search API 嗎? 我的需求是這樣的:在TextBox輸入要搜索的關(guān)鍵字,把搜索的結(jié)果顯示在Gridview里面。我的郵箱是guoxinliu917@gmail.com. 希望能得到你的幫助。謝謝!!!
          主站蜘蛛池模板: 新泰市| 白玉县| 越西县| 久治县| 峡江县| 巫山县| 浦北县| 花垣县| 化州市| 泗阳县| 克东县| 四子王旗| 淮安市| 行唐县| 永年县| 北流市| 新源县| 桐乡市| 广丰县| 普安县| 林西县| 齐河县| 察雅县| 盖州市| 高密市| 巴中市| 连山| 英超| 丰台区| 澄城县| 东辽县| 莱西市| 萍乡市| 阜南县| 青阳县| 潜山县| 平昌县| 富裕县| 襄樊市| 巴彦淖尔市| 盱眙县|