<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

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

    Google Map Api和GOOGLE Search Api整合擴展地圖本地搜索

    Posted on 2009-05-01 12:08 詩特林 閱讀(2848) 評論(1)  編輯  收藏 所屬分類: GIS

    http://www.playgoogle.com/post/44.html 
    將GOOGLE MAP API 和 GOOGLE Search API 進行整合,我用面向對象的方式寫了一個類,通過傳一個經緯度進去,自動通過GOOGLE LOCAL SEARCH獲取附近的相關信息。比如餐廳、景點等,反過來標到地圖上,并可在任意容器內顯示。

    下面是源碼:

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


    (
    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();

     

     點擊這里查看演示示例:經緯度查詢整合本地搜索


    評論

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

    2009-06-25 22:31 by Guoxin
    你好,你知道在window桌面怎樣用Google Search API 嗎? 我的需求是這樣的:在TextBox輸入要搜索的關鍵字,把搜索的結果顯示在Gridview里面。我的郵箱是guoxinliu917@gmail.com. 希望能得到你的幫助。謝謝?。?!
    主站蜘蛛池模板: 亚洲国产精品线观看不卡| 精品亚洲综合在线第一区| 亚洲国产成人久久77| 亚洲人成免费电影| 亚洲国产成人精品久久| h视频在线免费看| 色在线亚洲视频www| 久久精品女人天堂AV免费观看| 精品亚洲AV无码一区二区三区| 国产精品视频永久免费播放| 亚洲中文无码永久免| 热99re久久精品精品免费| 激情小说亚洲图片| 亚洲色偷拍区另类无码专区| a毛片免费全部在线播放** | 亚洲精品国产电影| 两性色午夜免费视频| 无码乱人伦一区二区亚洲一| 久久久久久精品免费看SSS| 亚洲免费福利在线视频| 国产一区二区三区在线免费观看| 乱爱性全过程免费视频| 久久夜色精品国产嚕嚕亚洲av| 亚洲视频免费一区| 亚洲砖码砖专无区2023 | 国产麻豆剧传媒精品国产免费| 免费国产在线精品一区 | 国产亚洲精品a在线观看app| 久久国产色AV免费观看| 亚洲成在人线aⅴ免费毛片| 久久久久久久亚洲精品| 在线观看的免费网站无遮挡| 亚洲精品色播一区二区| 亚洲色偷偷偷鲁综合| 免费H网站在线观看的| 免费人妻精品一区二区三区| 亚洲国产一区在线| 在线视频免费观看www动漫| 99久久国产精品免费一区二区 | 伊人久久免费视频| 亚洲AV无码之国产精品|