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

uniapp+微信小程序+地图+传入多个标记点显示+点击打开内置地图导航+完整代码

 一、效果展示

二、完整代码

<template>
	<view class="container">
		<map class="map-container" :latitude="latitude" :longitude="longitude" 
			:markers="markers" :controls="controls" show-location 
			@markertap="onMarkerTap">
		</map>
	</view>
</template>

<script>
export default {
	data() {
		return {
			latitude: 34.341568, // 默认中心点(西安)
			longitude: 108.940174,
			// 标记点(多个位置)
			markers: [
				{
					id: 1,
					latitude: 34.341568,
					longitude: 108.940174,
					title: "",
					iconPath: "/static/location.png", // 标记点图标
					width: 30,
					height: 30,
					callout: {
						content: "点击导航",
						color: "#ffffff",
						fontSize: 14,
						borderRadius: 10,
						bgColor: "#000000",
						padding: 8,
						display: "ALWAYS"
					}
				},
				{
					id: 2,
					latitude: 34.250568,
					longitude: 108.950174,
					title: "",
					iconPath: "/static/location.png",
					width: 30,
					height: 30,
					callout: {
						content: "点击导航",
						color: "#ffffff",
						fontSize: 14,
						borderRadius: 10,
						bgColor: "#000000",
						padding: 8,
						display: "ALWAYS"
					}
				}
			]
		};
	},
	methods: {
		// 点击标记点触发导航
		onMarkerTap(e) {
			const marker = this.markers.find(m => m.id === e.markerId);
			if (marker) {
				uni.openLocation({
					latitude: marker.latitude,
					longitude: marker.longitude,
					name: marker.title,
					address: marker.title,
					scale: 18
				});
			}
		}
	}
};
</script>

<style>
.container {
	width: 100vw;
	height: 100vh;
	overflow: hidden;
}

.map-container {
	width: 100%;
	height: 100%;
	position: absolute;
	top: 0;
	left: 0;
}
</style>

三、代码解释 

整体说一下就是map直接组件就显示地图,marker就是标记点传进来显示,uni.openLocation这个就是打开手机内置地图然后选择你的地图就能正常导航过去

相关文章:

  • 网络安全:利用 IP 查询构建网络安全系统的方法
  • 技术方案包括哪些内容
  • JavaAdv——多线程同步案例(售票系统)
  • OpenCV计算摄影学(16)调整图像光照效果函数illuminationChange()
  • BambuStudio学习笔记:KDTreeIndirect类
  • 数据库复习(第五版)- 第四章 数据库安全性
  • LeetCode hot 100—二叉树的中序遍历
  • 【JavaEE】SpringMVC简单练习
  • GTX 50系显卡cuda、pytorch环境配置
  • VMware ESX曝3个0Day漏洞,已被黑客利用
  • 股指期货的主要用途有哪些?
  • 百度权重有什么用?如何查看百度权重?
  • 20250306JIRA添加企业微信邮箱通知
  • C++ primier plus 第七节 函数探幽第一部分
  • Stable Diffusion教程|快速入门SD绘画原理与安装
  • 文本处理Bert面试内容整理-如何使用BERT进行微调?
  • linux0.11内核源码修仙传第四章——head.s
  • 长轮询和短轮询的区别?
  • WebAssembly技术及应用了解
  • 【硬件IIC与软件IIC在程序实现上的核心区别】结合STM32F103C8T6标准库代码进行对比分析
  • 特网站建设/杭州seo
  • 做网站温州/排名优化seo
  • 网站建设衤金手指花总/百度搜索提交入口
  • 营销型网站的建设/国际新闻界期刊
  • 网站建设设计简介/618网络营销策划方案
  • html做的网站排版导致乱码/河南网站优化公司