百度地圖移動端定位


// 手機定位,獲取設備經緯度,添加覆蓋物開始
let BMap = window.BMap
let geolocation = new BMap.Geolocation()
geolocation.enableSDKLocation() // 允許SDK輔助
geolocation.getCurrentPosition(function (r) {
if (this.getStatus() === 0) {
/*alert(r.address.city)// 獲取定位城市名稱
console.log(r.latitude) // 獲取緯度
console.log(r.longitude) // 獲取經度*/
var map = new BMap.Map('map');
var point = new BMap.Point(r.longitude,r.latitude);
map.centerAndZoom(new BMap.Point(r.longitude, r.latitude), 16);
map.addOverlay(new window.BMap.Marker(point))
}
})
// 手機定位,獲取設備經緯度,添加覆蓋物結束

 

 
         
         
       


免責聲明!

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



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