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 @   埃菲尔上的加菲猫  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示