1. 程式人生 > >百度地圖移動端定位

百度地圖移動端定位

// 手機定位,獲取裝置經緯度,新增覆蓋物開始
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))
}
})
// 手機定位,獲取裝置經緯度,新增覆蓋物結束