uniapp H5 打开地图 并选中标记点

发布于:2024-09-18 ⋅ 阅读:(25) ⋅ 点赞:(0)

uniapp H5 打开地图 并选中标记点

  1. 先上代码
			//打开地图 显示景区位置
			openMap() {
			    // 支付宝
				// #ifdef MP-ALIPAY
				my.openLocation({
					longitude: Number(this.detailObj.longitude), // 经度
					latitude: Number(this.detailObj.latitude), // 纬度
					name: this.detailObj.scenicName, // 标点名称
					address: this.detailObj.address, // 标点地址
					success: res => {
						// console.log(res);
					},
					fail: res => {
						// console.log(res);
					},
				});
				// #endif


				// 小程序
				// #ifdef MP-WEIXIN
				uni.openLocation({
					latitude: Number(this.detailObj.latitude), // 纬度
					longitude: Number(this.detailObj.longitude), // 经度
					name: this.detailObj.scenicName, // 标点名称
					success: function() {}
				});
				// #endif

                // H5------------------------------------------------------------------------------
                // this.detailObj.latitude // 纬度
                // this.detailObj.longitude // 经度
                // this.detailObj.scenicName // 标点名称
                
				// #ifdef H5
				uni.navigateTo({
					url:'/pages/webpage/webpage?urlEncode='+ encodeURIComponent(`https://uri.amap.com/marker?position=${this.detailObj.longitude},${this.detailObj.latitude}&name=${this.detailObj.scenicName}`)
				})
				// #endif
			},
  1. webview 页面/pages/webpage/webpage
<template>
	<view>
		<web-view :webview-styles="webviewStyles" :src="urlSrc"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				urlSrc:'',
				webviewStyles: {
					progress: {
						color: '#ff4643'
					}
				},
			};
		},
		onLoad(options) {
			if(options.urlEncode){
				this.urlSrc = decodeURIComponent(options.urlEncode)
				return
			}
		}
	}
</script>

  1. 这是高德提供的免费地址https://uri.amap.com/marker 高德官网

  2. 更多参数
    ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/35dcf64d9be8440191957efe1ee1f83b.p
    在这里插入图片描述

  3. 搞定 复制可用!感谢您的浏览!