vue直接使用高德api

第一步:在index.html 引入

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

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

javascript 复制代码
<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

相关推荐
GDAL11 分钟前
HTML 中的 Canvas 样式设置全解
javascript
m0_5287238117 分钟前
HTML中,title和h1标签的区别是什么?
前端·html
Dark_programmer18 分钟前
html - - - - - modal弹窗出现时,页面怎么能限制滚动
前端·html
GDAL23 分钟前
HTML Canvas clip 深入全面讲解
前端·javascript·canvas
禾苗种树24 分钟前
在 Vue 3 中使用 ECharts 制作多 Y 轴折线图时,若希望 **Y 轴颜色自动匹配折线颜色**且无需手动干预,可以通过以下步骤实现:
前端·vue.js·echarts
GISer_Jing29 分钟前
Javascript排序算法(冒泡排序、快速排序、选择排序、堆排序、插入排序、希尔排序)详解
javascript·算法·排序算法
贵州数擎科技有限公司1 小时前
使用 Three.js 实现流光特效
前端·webgl
JustHappy1 小时前
「我们一起做组件库🌻」做个面包屑🥖,Vue的依赖注入实战💉(VersakitUI开发实录)
前端·javascript·github
拉不动的猪1 小时前
刷刷题16
前端·javascript·面试
kiramario1 小时前
【结束】JS如何不通过input的onInputFileChange使用本地mp4文件并播放,nextjs下放入public文件的视频用video标签无法打开
开发语言·javascript·音视频