uniapp微信小程序使用地图选点插件

news/2024/7/20 3:22:16 标签: 前端, 微信小程序, 小程序

uniapp使用腾讯位置服务地图选点

文章目录

    • uniapp使用腾讯位置服务地图选点
      • 效果图
      • 1. 在公众平台申请插件
      • 2. 引入插件
      • 3. 设置定位授权:
      • 4. 使用插件

效果图

在这里插入图片描述


1. 在公众平台申请插件

  • 小程序>微信小程序官方后台-设置-第三方服务-插件管理” 里点击 添加插件,搜索 腾讯位置服务地图选点 申请,审核通过后,小程序开发者可在小程序内使用该插件。

2. 引入插件

  • pages.json中引入插件,根据个人需求,这里是在分包中引入插件
{
	"root": "hotel",
	"pages": [{}],
	"plugins": {
		"chooseLocation": {
			"version": "1.0.9",
			"provider": "wx76a9a06e5b4e693e" // 地图选点的APPID
		}
	}
}

3. 设置定位授权:

在这里插入图片描述


4. 使用插件

  • 根据个人需求调整,我这里新建一个页面调用插件,处理地图返回数据后,再返回上一页
  • 从地图选点插件返回后,在页面的onShow生命周期函数中能够调用插件接口,取得选点结果对象
<template>
	<view>
		
	</view>
</template>

<script>
	const chooseLocation = requirePlugin('chooseLocation');
	
	export default {
		data() {
			return {
				
			}
		},
		onLoad() {
			// 1. 插件页面调用
			let latLng = uni.getStorageSync('location');
			const key = this.$config.mpKey; // 使用在腾讯位置服务申请的key
			const referer = 'xx商城'; // 调用插件的app的名称
			const location = JSON.stringify({
			  latitude: latLng.latitude,
			  longitude: latLng.longitude
			});
			const category = '酒店宾馆,旅游景点';
			
			uni.navigateTo({
				url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}&category=${category}`
			})
		},
		onShow() {
			// 个人需求处理【A页面使用地图选点,点击跳转到此页面,得到数据后返回A页面】
			let tmpVisit = uni.getStorageSync('isVisit')
			if (!tmpVisit && tmpVisit != null) {
				uni.navigateBack({
					delta: 1
				})
			}
			
			// 2. 如果点击确认选点按钮,则返回选点结果对象,否则返回null
			const location = chooseLocation.getLocation();
			if (location) {
				uni.removeStorageSync('isVisit')
				this.$store.commit('setChooseAdr', location);
			}
		},
		onHide() {
			uni.setStorageSync('isVisit', false)
		},
		onUnload() {
			chooseLocation.setLocation(null);
		},
		methods: {
			
		}
	}
</script>

<style>

</style>

http://www.niftyadmin.cn/n/1581725.html

相关文章

日期格式转时间戳

日期格式转时间戳 timeTurnTimeStamp(string) {var f string.split( , 2);var d (f[0] ? f[0] : ).split(-, 3);var t (f[1] ? f[1] : ).split(:, 3);return (new Date(parseInt(d[0], 10) || null,(parseInt(d[1], 10) || 1) - 1,parseInt(d[2], 10) || null,parseInt(t…

深拷贝对象2

深拷贝对象 deepClone(obj) {// 判断是否为对象if (obj null) return null;if (typeof obj ! object) return obj;// 判断是否为Date类型if (obj instanceof Date) {let date new Date();date.setTime(obj.getTime());return date;}let cloneObj new obj.constructor();for…

uniapp获取当前的地理位置

uniapp获取当前的地理位置 — 不管几岁&#xff0c;快乐万岁— 文章目录uniapp获取当前的地理位置相关文档效果图抽取JS文件使用相关文档 getlocation authorize 注意&#xff1a; uni.authorize不支持APP/H5&#xff0c;具体看文档&#xff0c;这里介绍用于微信小程序~ 效果…

uniappr使用swiper实现监听多个菜单滑动

uniapp使用swiper实现多个菜单滑动 文章目录uniapp使用swiper实现多个菜单滑动效果图templatejscssswiper文档 效果图 概述 通过swiper中previous-margin属性设置边距根据需求调整样式&#xff0c;及默认选中项 template <view class"couponWrap"><view …

css3实现无缝滚动

css3实现无缝滚动 文章目录css3实现无缝滚动横向滚动纵向滚动元素横向滚动 <view class"move-box"><view class"move"><view class"item" v-for"(item, index) in 2" :key"index">{{index}}寒雨连江夜入…

uniapp使用swiper根据动态数据实现分页

uniapp使用swiper根据动态数据实现分页 文章目录uniapp使用swiper根据动态数据实现分页效果图templatejscss效果图 template 使用Math.ceil()向上取整&#xff0c; 这里测试每页8条通过slice()提取字符串的某个部分 <view class"swiper-box"><swiper clas…

scss @for与rgba函数巧妙使用

SCSS for与rgba函数使用 这里再次记录下~~~ 文章目录SCSS for与rgba函数使用效果图templatejsscss其他用法each参数变量...占位符选择器 %fooat-root效果图 template <template><view class"list"><view class"item" :class"[item-${…

uniapp使用scroll-view实现左右分类联动

uniapp实现左右分类联动 仅供参考&#xff0c;根据个人所需调整 文章目录uniapp实现左右分类联动效果图分类内容数据格式效果图templatejscss效果图 分类内容数据格式效果图 rectInfoList数据内容 template <template><view class""><view class&qu…