uniapp地图点击获取位置

主页面

javascript 复制代码
<view class="right-content" @click.stop="kilometer(item)">
	<view class="km">
     {{item.distance||'0'}}km
	</view>
	<image src="../../static/map.png" mode=""
		style="width: 32rpx; height: 32rpx; margin-left: 10rpx; margin-right: 10px;">
	</image>
</view>
   kilometer(item){
		uni.navigateTo({
			url: `/subpkg/map/map?item=${(JSON.stringify(item))}`,
		})
	},

点击跳转的页面

javascript 复制代码
<template>
	<view>
		<map style="width: 100%; height: 400px;" enable-building="true" show-compass="true" :latitude="latitude"
			:longitude="longitude" :markers="markers">
		</map>
	</view>
</template>

<script>
	export default {
		data() {
			return {

				latitude: 0,
				longitude: 0,
				markers: [{
					id: 1,
					latitude: 0,
					longitude: 0,
					width: '30', // 标记点图标宽度
					height: '50' // 标记点图标高度
				}],
				msgInfo: {}
			}

		},
		onLoad(option) {
			this.msgInfo = JSON.parse(option.item || '{}');
			this.latitude = Number(this.msgInfo.lat || 0);
			this.longitude = Number(this.msgInfo.lng || 0);

			// 更新 covers 数组中的标记点位置  
			this.markers[0].latitude = this.latitude;
			this.markers[0].longitude = this.longitude;


		}
	}
</script>

<style lang="scss">

</style>
相关推荐
游戏开发爱好者88 小时前
抓包工具有哪些?代理抓包、数据流抓包、拦截转发工具
android·ios·小程序·https·uni-app·iphone·webview
郑州光合科技余经理12 小时前
技术解析:如何打造适应多国市场的海外跑腿平台
java·开发语言·javascript·mysql·spring cloud·uni-app·php
前端 贾公子13 小时前
uniapp之实现拖拽排序
uni-app
一室易安13 小时前
uniapp vue3 小程序中 手写模仿京东淘宝加入购物车红点曲线飞入样式效果 简化版代码
小程序·uni-app
00后程序员张14 小时前
混合 App 怎么加密?分析混合架构下常见的安全风险
android·安全·小程序·https·uni-app·iphone·webview
2501_9159214315 小时前
Flutter App 到底该怎么测试?如何在 iOS 上进行测试
android·flutter·ios·小程序·uni-app·cocoa·iphone
2501_9159090616 小时前
如何在 Windows 上上架 iOS App,分析上架流程哪些是不用mac的
android·macos·ios·小程序·uni-app·iphone·webview
2501_9159214316 小时前
分析 iOS 描述文件创建与管理中常见的问题
android·ios·小程序·https·uni-app·iphone·webview
Aftery的博客17 小时前
Uniapp-vue实现语言功能切换(多语言)
javascript·vue.js·uni-app
我这一生如履薄冰~2 天前
uni-app 项目配置代理踩坑
uni-app