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

一、效果展示

二、完整代码

javascript 复制代码
<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这个就是打开手机内置地图然后选择你的地图就能正常导航过去

相关推荐
小徐_233318 小时前
Open Wot 1.0.5 发布:让 AI 接入 wot-ui,只需要两条命令
前端·uni-app·ai编程
AI多Agent协作实战派21 小时前
AI多Agent协作系统实战(二十二):从6列到12列——任务监控报告的进化之路
java·人工智能·uni-app·bug
小杨小杨、努力变强!1 天前
VS Code运行HBuilder X中的uni-app项目
vscode·uni-app·uni-app run
码兄科技1 天前
实战:基于Spring Boot + UniApp的地理信息小程序开发
spring boot·后端·uni-app
2501_916007472 天前
iOS和macOS应用程序性能分析和优化工具使用综合指南
android·macos·ios·小程序·uni-app·iphone·webview
2501_916007473 天前
深入理解HTTPS对称与非对称加密机制及Charles抓包实践
网络协议·http·ios·小程序·https·uni-app·iphone
小徐_23333 天前
AI 写 wot-ui 总在猜 API?我们把 Skills、MCP 和 CLI 都配好了
前端·uni-app·ai编程
Liu.7743 天前
uni-app 组件 uni-easyinput 常见 Bug 及解决方案
uni-app·bug
小徐_23333 天前
uni-app 项目别再从零搭了!3 个 Wot UI 起手模板怎么选?
前端·uni-app
蜡台4 天前
uniapp pdf文件预览组件
pdf·uni-app·合同·pdfh5