vue项目引入百度地图

1.html文件中添加代码

<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=申请的key&services=false"></script>

地址:https://lbsyun.baidu.com/apiconsole/key

2.vue.config.js中添加

 3.使用 获取当前城市名称

// 获取城市名称
            const geolocation = new BMap.Geolocation();
            var _this = this
            geolocation.getCurrentPosition(function getinfo(position){
                _this.city = position.address.city;             //获取城市信息
                _this.getWeather()
            }, function(e) {
                _this.LocationCity = "定位失败"
            }, {provider: 'baidu'});

 注:使用edge浏览器可能会报错

 查看浏览器是否设置为严格模式,需要更改为平衡模式

 

posted @ 2025-01-13 18:54  埃菲尔上的加菲猫  阅读(10)  评论(0)    收藏  举报