当前位置: 首页 > news >正文

vue直接使用高德api

第一步:在index.html 引入

 <script src="https://webapi.amap.com/maps?v=2.0&key=你的key"></script>

第二步:在你需要地图的时候 放入

<template><div style="width: 200px; height: 200px"><div id="container"></div></div>
</template><script>export default {data() {return {map: '',zoom: 9,markers: [],markers1: [],center: [121.47, 31.23]};},mounted() {this.map = new AMap.Map('container', {viewMode: '2D',zoom: this.zoom,center: this.center,mapStyle: 'amap://styles/blue'});this.map.on('zoomchange', this.mapZoom);},methods: {mapZoom() {this.zoom = parseInt(this.map.getZoom()); //获取当前地图级别console.log('this.zoom', this.zoom);},markerAllhl() {this.map.clearMap();this.markers = [{ position: [121.436531, 31.231003], title: '王斐', content: '王斐' },{ position: [121.460826, 31.222186], title: '许思睿', content: '许思睿' },{ position: [121.450816, 31.252146], title: '彭晔', content: '彭晔' },{ position: [121.480821, 31.282148], title: '林洁', content: '林洁' },{ position: [121.49082, 31.222149], title: '冯霞', content: '冯霞' },{ position: [121.410817, 31.214155], title: '王怡娜', content: '王怡娜' },{ position: [121.460818, 31.222147], title: '徐依媛', content: '徐依媛' },{ position: [121.46082, 31.222149], title: '张如真', content: '张如真' },{ position: [121.46125, 31.233147], title: '周韵', content: '周韵' },{ position: [121.469477, 31.277148], title: '徐天怿', content: '徐天怿' }]; for (const markerInfo of  this.markers) {const markerPosition = markerInfo.position; // 标记点的位置const markerTitle = markerInfo.title; // 标记点的标题const markerContent = markerInfo.content; // 标记点的内容const markerIcon = new AMap.Icon({image: 'https://webapi.amap.com/images/mass/mass0.png',size: new AMap.Size(20, 20),imageSize: new AMap.Size(20, 20)});this.marker = new AMap.Marker({icon: markerIcon,position: markerPosition});this.marker.setTitle(markerTitle);// this.marker.setContent(markerContent);this.marker.setMap(this.map);// 添加点击事件监听器this.marker.on('click', () => {// 在点击事件中处理你想要的操作,例如弹出信息窗口等console.log('Marker Clicked:', markerTitle, markerContent);});}},}
};
</script><style scoped>
html,
body,
#container {width: 100%;height: 100%;
}</style>

 以上就是 如果需要其他的方法 请 访问 官网  

概述-地图 JS API 2.0 | 高德地图API

http://www.lryc.cn/news/139111.html

相关文章:

  • Setting
  • 时序预测 | Matlab实现SO-CNN-BiGRU蛇群算法优化卷积双向门控循环单元时间序列预测
  • 论文浅尝 | KRACL-利用图上下文和对比学习的稀疏KG补全
  • 【C++】右值引用,移动语义,完美转发
  • 【AI】即使AI 时代,程序员也无需焦虑
  • Django实现DRF数据API接口格式封装
  • [Go版]算法通关村第十三关白银——数字数学问题之数组实现加法、幂运算
  • 【 OpenGauss源码学习 —— 列存储(Insert)】
  • Android 13.0 framework中实现默认长按电源键弹出关机对话框功能
  • 微信小程序,封装身高体重选择器组件
  • 深度学习调参技巧
  • 图论基础和表示(Java 实例代码)
  • 各种数据库查询报错问题
  • 人效九宫格城市沙龙暨《人效九宫格白皮书》发布会 —上海站,圆满结束
  • 【C语言】文件操作 -- 详解
  • 飞天使-k8s基础组件分析-持久化存储
  • python连接PostgreSQL 数据库
  • 数字图像处理—— Lab、YCbCr、HSV、RGB之间互转
  • 自动驾驶SLAM技术第四章习题2
  • vue拖拽div盒子实现上下拖动互换
  • Visual Studio 2022 右键单击项目没有出现View | View Class Diagram(Visual Studio 无法使用类设计器)
  • EFCore常见用法
  • 概率论与数理统计:第六章:数理统计
  • 拥塞控制(TCP限制窗口大小的机制)
  • 校园供水系统智能管理
  • Flask-SocketIO和Flask-Login联合开发socketio权限系统
  • 航空电子设备中的TSN通讯架构—直升机
  • elment-ui中使用el-steps案例
  • FPGA解析串口指令控制spi flash完成连续写、读、擦除数据
  • msvcp120.dll丢失的解决方法,分享三种快速修复的方法