百度地圖(36)-GL 關鍵字搜索


1. 關鍵字搜索包括本地搜索,附件搜索,范圍搜索(矩形、圓形等) 。

 

2. 關鍵字搜索使用的BMapGL.LocalSearch。

 可以指定結果顯示的div。

 另外測試了幾次,js代碼必需和html文件寫在同一個文件里,

 否則在地圖無法顯示搜索結果標注,就是那個小紅標,不知道為什么。

 以后再研究。

 

3. 代碼參考

 1   /**
 2    * POI搜索
 3    */
 4   function poiSearch(){
 5     clearSearch();
 6     local = new BMapGL.LocalSearch(map,searchOpts);
 7     local.search("公園");
 8   };
 9 
10   /**
11    * 附近搜索
12    */
13   function nearbySearch(){
14     clearSearch();
15     local = new BMapGL.LocalSearch(map,searchOpts);
16     local.searchNearby("酒店","北京大學");
17   };
18 
19   /**
20    * 范圍查詢
21    */
22   function inBoundSearch(){
23     clearSearch();
24     map.centerAndZoom(new BMapGL.Point(116.274625,39.961627), 13);
25 
26     local = new BMapGL.LocalSearch(map,searchOpts);
27     var pStart = new BMapGL.Point(116.274625,39.961627);
28     var pEnd = new BMapGL.Point(116.367474,39.988609);
29     var bs = new BMapGL.Bounds(pStart,pEnd);   //自己規定范圍
30 
31     local.searchInBounds("銀行",bs);
32     var polygon = new BMapGL.Polygon([
33       new BMapGL.Point(pStart.lng,pStart.lat),
34       new BMapGL.Point(pEnd.lng,pStart.lat),
35       new BMapGL.Point(pEnd.lng,pEnd.lat),
36       new BMapGL.Point(pStart.lng,pEnd.lat)
37     ], {strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5});
38     map.addOverlay(polygon);
39   };

 

4. 頁面顯示

 

 

 

 

 

5. 源碼地址

https://github.com/WhatGIS/bdMap

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM