百度地圖(34)-GL 定位


1. 三維定位同二維定位類似,也包括瀏覽器定位、IP定位、SDK輔助定位。

 

2. 瀏覽器定位

 1   /**
 2    * 瀏覽器定位
 3    */
 4   function geoLocation() {
 5     var geoLocation = new BMapGL.Geolocation();
 6     geoLocation.getCurrentPosition(function (r) {
 7       if(this.getStatus() == BMAP_STATUS_SUCCESS){
 8         var mk = new BMapGL.Marker(r.point);
 9         map.addOverlay(mk);
10         map.panTo(r.point);
11         alert('您的位置:' + r.point.lng + "," + r.point.lat);
12       }
13       else {
14         alert('failed' + this.getStatus());
15       }
16     });
17   }

 

3. IP定位

 1  /**
 2    * IP定位
 3    */
 4   function cityLocation() {
 5     function myFun(result) {
 6       var cityName = result.name;
 7       map.setCenter(cityName);
 8       alert("當前城市"+cityName);
 9     }
10     var myCity = new BMapGL.LocalCity();
11     myCity.get(myFun);
12   }

 

4. 輔助定位

 1  /**
 2    * SDK輔助定位
 3    */
 4   function sdkLocation() {
 5     var geoLocation = new BMapGL.Geolocation();
 6     geoLocation.enableSDKLocation();
 7     geoLocation.getCurrentPosition(function (r) {
 8       if(this.getStatus() == BMAP_STATUS_SUCCESS){
 9         var mk = new BMapGL.Marker(r.point);
10         map.addOverlay(mk);
11         //map.panTo(r.point);
12         console.log('您的新位置:' + r.point.lng + "," + r.point.lat);
13       }
14       else {
15         alert('failed' + this.getStatus());
16       }
17     });
18   }

 

5. 頁面顯示

 

 

6. 源碼地址

https://github.com/WhatGIS/bdMap


免責聲明!

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



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