1.在index.html中写
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"></script>
2.在lib里面封装一个getLocation.js
let getCurrentCityName = function() {
return new Promise(function(resolve, reject) {
let myCity = new BMap.LocalCity()
myCity.get(function(result) {
resolve(result.name)
})
})
}
export default getCurrentCityName
3.在你需要定位的文件里面写
mounted(){
getCurrentCityName().then((city)=>{
this.locations = city;
})
}
网友评论