定位功能 js和vue里引用百度地图

定位功能 js和vue里引用百度地图

1、在index.html引入百度地图API
定位功能 js和vue里引用百度地图_第1张图片

 <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=密钥"></script>

2、map方法调用
定位功能 js和vue里引用百度地图_第2张图片

getAddress() {
   this.map = new window.BMap.Map('allmap')
   var myCity = new window.BMap.LocalCity()
   myCity.get(this.myFun)
        },
myFun(result) {
   const _this = this
   var geolocation = new BMap.Geolocation();
   geolocation.getCurrentPosition(function(r) {
       // console.log(r)
       if (this.getStatus() == BMAP_STATUS_SUCCESS) {
           _this.placeGeolocation = r.point.lat+ "," + r.point.lng;
       } else {
           Toast("定位失败,请手动填写地点!");
           return;
       }
       var nowGeolocation = r.address.province + r.address.city + r.address.district + r.address.street + r.address.street_number;
      
   }, {
       enableHighAccuracy : true
   }) //指示浏览器获取高精度的位置,默认false
},

结束,希望对你有帮助!

你可能感兴趣的:(定位,js,vue,百度)