<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

        Google(Local)SearchAPI的簡(jiǎn)單使用介紹_javascript技巧

        來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 21:16:30
        文檔

        Google(Local)SearchAPI的簡(jiǎn)單使用介紹_javascript技巧

        Google(Local)SearchAPI的簡(jiǎn)單使用介紹_javascript技巧:花了兩天的時(shí)間來用Google的API來做這么一個(gè)小東西,其實(shí)真正的實(shí)現(xiàn)代碼不是很多,十幾行而已。費(fèi)時(shí)間的工作是了解各個(gè)API的功能以及調(diào)試JavaScript。 下面簡(jiǎn)單介紹一下這次我用到的幾個(gè)函數(shù)吧。 •構(gòu)造函數(shù)google.search.LocalSearc
        推薦度:
        導(dǎo)讀Google(Local)SearchAPI的簡(jiǎn)單使用介紹_javascript技巧:花了兩天的時(shí)間來用Google的API來做這么一個(gè)小東西,其實(shí)真正的實(shí)現(xiàn)代碼不是很多,十幾行而已。費(fèi)時(shí)間的工作是了解各個(gè)API的功能以及調(diào)試JavaScript。 下面簡(jiǎn)單介紹一下這次我用到的幾個(gè)函數(shù)吧。 •構(gòu)造函數(shù)google.search.LocalSearc

        花了兩天的時(shí)間來用Google的API來做這么一個(gè)小東西,其實(shí)真正的實(shí)現(xiàn)代碼不是很多,十幾行而已。費(fèi)時(shí)間的工作是了解各個(gè)API的功能以及調(diào)試JavaScript。

        下面簡(jiǎn)單介紹一下這次我用到的幾個(gè)函數(shù)吧。

        •構(gòu)造函數(shù)google.search.LocalSearch()

        這其實(shí)是創(chuàng)建了一個(gè)LocalSearch的Service,這個(gè)Service和其他Service(News, Blog, Web)一樣,是供SearchControl使用的。這些Service決定了SearchControl的能力。

        •設(shè)置LocalSearch的搜索結(jié)構(gòu)類型

        localSearch.setRestriction(google.search.Search.RESTRICT_TYPE, google.search.LocalSearch.TYPE_KMLONLY_RESULTS)

        這說明搜索的結(jié)果沒有business的結(jié)果,只有kml和geocode結(jié)果

        •設(shè)置LocalSearch的搜索范圍

        localSearch.setCenterPoint("北京");

        •google.search.SearcherOptions()

        設(shè)置Search Service(Searcher)的屬性,作為SearchControl.addSearcher()的一個(gè)屬性使用,有以下選項(xiàng)可以選擇:


        1.設(shè)置結(jié)果的顯示方式
        •searcherOptions.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);

        2. 設(shè)置檔沒有搜索結(jié)果時(shí)顯示的文字

        • searcherOptions.setNoResultsString(google.search.SearchControl.NO_RESULTS_DEFAULT_STRING);

        3. 設(shè)置結(jié)果顯示的位置

        •searcherOptions.setRoot(resultCanvas);

        •new google.search.DrawOptions();

        設(shè)置Google Search Control的顯示方式

        •drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED)

        設(shè)置顯示方式為tabbed方式,即各個(gè)Searcher像tabs一樣顯示

        •drawOptions.setInput(document.getElementById("input"));

        將搜索輸入框的默認(rèn)值改為用戶自定義的一個(gè)輸入框


        將用戶選擇搜索結(jié)果作為一個(gè)相應(yīng)的GResult對(duì)象返回,如LocalSearch的GResult就是一個(gè)GLocalResult。

        這個(gè)選項(xiàng)費(fèi)了我很長(zhǎng)時(shí)間才找到,原因有二,一是用的人少,文檔少。二是我看的英文文檔,花了挺長(zhǎng)時(shí)間才看明白,其實(shí)看中文文檔要花的時(shí)間更長(zhǎng),我覺得。

        •searchControl.setOnKeepCallback(this, LocalSearchKeepHandler);

        順便貼上LocalSearchKeepHandler的代碼,其參數(shù)為自動(dòng)返回的那個(gè)GResult對(duì)象。
        代碼如下:
        function LocalSearchKeepHandler(result) {
        var from = document.getElementById("from");
        alert("result.tilte = " + result.title);
        from.value = ProcessString(result.title);
        alert("from.value = " + from.value);
        // alert(result.title);
        }

        干脆把這段代碼整體貼出,方便閱讀
        代碼如下:
        google.load("search", "1", {"language": "zh-CN"});
        function initialize() {
        //LocalSearch Object used to create a local search service for the maps
        var localSearch = new google.search.LocalSearch();
        //restrict the local search resutls to kml and geocode results only, no business ones
        localSearch.setRestriction(google.search.Search.RESTRICT_TYPE, google.search.LocalSearch.TYPE_KMLONLY_RESULTS);
        // Set the Local Search center point
        localSearch.setCenterPoint("北京");
        //It's about local search, which are used to set where the results will appear, a param of options
        var resultCanvas = document.getElementById("resultCanvas");
        //options: open, alternate root
        var searcherOptions = new google.search.SearcherOptions();
        //show many results
        searcherOptions.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
        //no results message
        searcherOptions.setNoResultsString(google.search.SearchControl.NO_RESULTS_DEFAULT_STRING);
        //options.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);//web, local... in a tab show
        searcherOptions.setRoot(resultCanvas); //show the results in another place--
        //SearchControl Object used to create a search service which will include a local search service
        var searchControl = new google.search.SearchControl(null);
        searchControl.addSearcher(localSearch, searcherOptions);
        searchControl.addSearcher(new google.search.WebSearch());
        searchControl.addSearcher(new google.search.NewsSearch());
        searchControl.addSearcher(new google.search.BlogSearch());
        //draw options and set it to a tabbed view,
        var drawOptions = new google.search.DrawOptions();
        drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED)
        //make the searchControl return a result:GResult
        searchControl.setOnKeepCallback(this, LocalSearchKeepHandler);//keeping a search result
        //this option is used to set the search box position in a DOM tree.
        //drawOptions.setSearchFormRoot(document.getElementById("drawOptions"));
        //set the input box to a user defined element
        //drawOptions.setInput(document.getElementById("input"));
        // tell the search box to draw itself and tell it where to attach
        // searchControl.draw(document.getElementById("searchBox"), drawOptions);//Here I changed fromaddress and toaddress to search, a new place
        //another user defined input box
        drawOptions.setInput(document.getElementById("input2"));
        searchControl.draw();
        /** The codes below is about google Ajax Map Search API
        //this code segment is used to add a sidebar to show the results of the search
        //I wonder why no 'var' exists here
        optinos = new Object();
        options.resultList = resultCanvas;
        options.resultFormat = "multi-line1";
        var lsc2 = new google.elements.LocalSearch(options);
        map.addControl(lsc2, new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(-282, -2)));
        */
        }
        google.setOnLoadCallback(initialize);

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Google(Local)SearchAPI的簡(jiǎn)單使用介紹_javascript技巧

        Google(Local)SearchAPI的簡(jiǎn)單使用介紹_javascript技巧:花了兩天的時(shí)間來用Google的API來做這么一個(gè)小東西,其實(shí)真正的實(shí)現(xiàn)代碼不是很多,十幾行而已。費(fèi)時(shí)間的工作是了解各個(gè)API的功能以及調(diào)試JavaScript。 下面簡(jiǎn)單介紹一下這次我用到的幾個(gè)函數(shù)吧。 •構(gòu)造函數(shù)google.search.LocalSearc
        推薦度:
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲AV无码之国产精品| 中文字幕乱码亚洲精品一区| 免费一区二区无码视频在线播放 | 看亚洲a级一级毛片| 国内精品免费视频自在线| 日韩亚洲不卡在线视频中文字幕在线观看| 四虎在线视频免费观看视频| 亚洲最大视频网站| 国内外成人免费视频| 国产亚洲综合一区二区三区| 免费中文字幕在线| 国产免费A∨在线播放| 亚洲日韩av无码| 99久久精品免费精品国产| 亚洲第一香蕉视频| 毛片在线免费视频| 黄色片网站在线免费观看| 亚洲一区二区视频在线观看| 任你躁在线精品免费| 亚洲精品人成在线观看| av无码国产在线看免费网站| 亚洲人成网亚洲欧洲无码| 免费一级毛片正在播放| 免费无码又爽又刺激网站| 91亚洲国产成人久久精品| 国产一区视频在线免费观看| 黄床大片免费30分钟国产精品| 亚洲Aⅴ无码专区在线观看q| 日本成年免费网站| 特级毛片在线大全免费播放| 亚洲第一中文字幕| 国产精品免费视频一区| 在线观看肉片AV网站免费| 亚洲欧洲另类春色校园网站| 亚洲А∨精品天堂在线| 无码精品一区二区三区免费视频| 亚洲国产综合自在线另类| 无码专区一va亚洲v专区在线| 99久久精品国产免费| 国产精品亚洲专区在线播放| 亚洲一区二区三区夜色|