1.根目录html文件引入
<!--引入百度 API,"ak=" 后面一串码是密钥,最好自己申请-->
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=7a6QKaIilZftIMmKGAFLG7QT1GLfIncg"></script>
2.vue页面
methods:
getLocation() {
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(e){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
var geoc = new BMap.Geocoder()
// 百度 geolocation 的经纬度属性不同,此处是 point.lat 而不是 coords.latitude
let LocationProvince = e.address.province
let LocationCity = e.address.city
console.log(LocationProvince,LocationCity)
}else{
this.getStatus();
}
})
},