// 手机定位,获取设备经纬度,添加覆盖物开始let BMap = window.BMaplet 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)) }})// 手机定位,获取设备经纬度,添加覆盖物结束
来源:https://www.cnblogs.com/yegeng/p/10191020.html