vue接入高德地图

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

index.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配置

	# 前端服务
     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/;
         }
   }

使用

	new AMap.Map('mapContainer', {
      zoom: 10,
      center: [108.931284, 34.382289]
    })
  • 8
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的 Vue 接入高德地图选点的示例: 1. 在 index.html 中引入高德地图的 js 文件 ``` <script src="//webapi.amap.com/maps?v=1.4.10&key=your-amap-key"></script> ``` 2. 在 App.vue 中创建地图容器和初始化地图 ``` <template> <div id="map-container"></div> </template> <script> export default { mounted() { // 创建地图容器 const map = new AMap.Map("map-container", { zoom: 10 }); // 初始化地图 AMap.plugin("AMap.Geolocation", () => { const geolocation = new AMap.Geolocation({ enableHighAccuracy: true, // 是否使用高精度定位,默认:true timeout: 10000, // 超过10秒后停止定位,默认:5s buttonPosition: "RB", // 定位按钮的停靠位置 zoomToAccuracy: true // 定位成功后是否自动调整地图视野到定位点 }); map.addControl(geolocation); geolocation.getCurrentPosition(); }); } }; </script> ``` 3. 添加选点功能 ``` <template> <div> <div id="map-container"></div> <div> <button @click="choosePoint">选点</button> <span>经度: {{ location.lng }}</span> <span>纬度: {{ location.lat }}</span> </div> </div> </template> <script> export default { data() { return { location: {} // 保存选定的经纬度 }; }, mounted() { const map = new AMap.Map("map-container", { zoom: 10 }); AMap.plugin("AMap.Geolocation", () => { const geolocation = new AMap.Geolocation({ enableHighAccuracy: true, timeout: 10000, buttonPosition: "RB", zoomToAccuracy: true }); map.addControl(geolocation); geolocation.getCurrentPosition(); }); }, methods: { choosePoint() { // 定义选点插件 const geolocation = new AMap.Geolocation({ enableHighAccuracy: true, timeout: 10000, buttonPosition: "RB", zoomToAccuracy: true }); // 打开选点插件 map.addControl(geolocation); geolocation.getCurrentPosition(); // 监听选点事件 AMap.event.addListener(geolocation, "complete", result => { this.location.lng = result.position.lng; this.location.lat = result.position.lat; }); } } }; </script> ``` 希望这个示例对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值