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

相关推荐
游戏开发爱好者83 小时前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
2501_915106324 小时前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106325 小时前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
宠友信息6 小时前
2025社交+IM及时通讯社区APP仿小红书小程序
java·spring boot·小程序·uni-app·web app
“负拾捌”6 小时前
python + uniapp 结合腾讯云实现实时语音识别功能(WebSocket)
python·websocket·微信小程序·uni-app·大模型·腾讯云·语音识别
局外人LZ1 天前
Uniapp脚手架项目搭建,uniapp+vue3+uView pro+vite+pinia+sass
前端·uni-app·sass
2501_915918411 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
前端呆头鹅1 天前
Websocket使用方案详解(uniapp版)
websocket·网络协议·uni-app
浮桥1 天前
uniapp+h5 公众号实现分享海报绘制
uni-app·notepad++
2501_916007471 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview