[uniapp] The applet uses map positioning to obtain the location and display it on the page

insert image description here
1. First go to the WeChat public platform to activate
insert image description here
2. Then add a plug-in, search for 'Tencent Location Service Map Selection', and click Add
insert image description here
3. Go to apply for a developer key
https://lbs.qq.com?lbs_invite=Y9PRFLY

4. Configure the plug-in in uniapp or report an error, the provider is written to death wx76a9a06e5b4e693e
insert image description here

The following is the page display processing, which is to obtain the location and then assign the page display

onShow() {
    
    
			const location = chooseLocation.getLocation();
			//conole.log(location )
			if (location) {
    
    
				//location.address和location.name都是地理位置
				this.position = location.address + location.name
			}
		},

a click event

_getusermapinfo() {
    
    
				uni.getLocation({
    
    
						type: 'gcj02',//腾讯地图使用gcj02获取位置坐标
						success(res) {
    
    
							//使用在腾讯位置服务申请的key(必填)
							const key = "自己申请的KEY";
							//调用插件的app的名称(必填)
							const referer = "app名称";
							wx.navigateTo({
    
    
								url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer,
							});
						},
						fail(err) {
    
     //这里处理用户点击拒绝或者误操作拒绝的办法
							 uni.showModal({
    
    
							 	title: '提示',
							 	content: '您未开启获取位置权限,请点击确定去开启权限!',
							 	success(res) {
    
    
							 	    if (res.confirm) {
    
    
							 		 uni.openSetting({
    
    })//跳转微信小程序设置,手动打开获取位置
							    	 }
							 	}
							 })
							 
						}
				})
			},

Guess you like

Origin blog.csdn.net/weixin_48772762/article/details/117220665