vue接入高德地图

使用 JSAPI 安全模式,代理服务请以_AMapService 作为一级路由

index.html

html 复制代码
  <script type="text/javascript">
    window._AMapSecurityConfig = {
      serviceHost: "http://xx.xx.xx.xx:8223/_AMapService"
    };
  </script>
  <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=你的高德key"></script>

nginx配置

Nginx 复制代码
	# 前端服务
     server {
         listen       8223;
         server_name  8223;
         charset utf-8;
 
		  location / {
                 root   /root/qianduan/前端代码;
                 try_files $uri $uri/ /index.html;
                 index  index.html index.htm;
                 add_header Access-Control-Allow-Origin *;
         }

        location /_AMapService/v4/map/styles {
             set $args "$args&jscode=你自己的安全密钥";
             proxy_pass http://webapi.amap.com/v4/map/styles;
         }
 
         # 海外地图服务代理
         location /_AMapService/v3/vectormap {
             set $args "$args&jscode=你自己的安全密钥";
             proxy_pass http://fmap01.amap.com/v3/vectormap;
         }
 
         # Web服务API 代理
         location /_AMapService/ {
             set $args "$args&jscode=你自己的安全密钥";
             proxy_pass http://restapi.amap.com/;
         }
   }

使用

js 复制代码
	new AMap.Map('mapContainer', {
      zoom: 10,
      center: [108.931284, 34.382289]
    })
相关推荐
拾光拾趣录23 分钟前
从“祖传”构造函数到 `class`
前端·javascript
wmm_会飞的@鱼28 分钟前
FlexSim-汽车零部件仓库布局优化与仿真
服务器·前端·网络·数据库·数学建模·汽车
yvvvy30 分钟前
从“按钮都不会点”到“能撸大厂 UI”:我用 react-vant 踢开组件库的大门!
前端·javascript
安然dn31 分钟前
Cropper.js:JS图像裁剪库
前端·javascript
Serendipity26133 分钟前
微服务架构
前端·微服务
Hilaku1 小时前
深入background-image:你可能不知道的几个性能优化与高级技巧
前端·css
南岸月明1 小时前
副业自媒体1年终于明白:为什么会表达的人,能量越来越强,更能赚到钱?
前端
Danny_FD1 小时前
Vue + Element UI 实现模糊搜索自动补全
前端·javascript
gnip1 小时前
闭包实现一个简单Vue3的状态管理
前端·javascript
斐济岛上有一只斐济1 小时前
后端程序员的CSS复习
前端