uniapp中获取位置取消授权问题chooseLocation:fail auth deny

记录uni-app开发小程序 用户取消弹框的权限,后边就不出权限弹框,而且也不报错,直接走fail问题:

getLocation(){
	uni.chooseLocation({
	    success: (res) =>{
	        console.log('位置名称:' + res.name);
	        console.log('详细地址:' + res.address);
	        console.log('纬度:' + res.latitude);
	        console.log('经度:' + res.longitude);
			this.latitude = res.latitude
			this.longitude = res.longitude
			this.weizhiName = res.address
	    },
		fail: () => {
				// 获取用户当前授权设置
				uni.getSetting({
					success: function(res) {
						var statu = res.authSetting;
						console.log(statu);
						if (!statu['scope.userLocation']) {
							console.log(123);
							uni.showModal({
								title: '是否授权当前位置',
								content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
								success(tip) {
									if (tip.confirm) {
										// 打开用户授权设置
										uni.openSetting({
											success: function(data) {
												if (data.authSetting["scope.userLocation"] === true) {
													uni.showToast({
														title: '授权成功',
														icon: 'success',
														duration: 1000
													})
													//授权成功之后,再调用chooseLocation选择地方
													setTimeout(function() {
														uni.chooseLocation({
															success: (data) => {
																console.log('位置名称:' + data.name);
																console.log('详细地址:' + data.address);
																console.log('纬度:' + data.latitude);
																console.log('经度:' + data.longitude);
																this.latitude = data.latitude
																this.longitude = data.longitude
																this.weizhiName = data.address
															}
														})
													}, 1000)
												}
											}
										})
									} else {
										wx.showToast({
											title: '授权失败',
											icon: 'none',
											duration: 1000
										})
									}
								}
							})
		 
						}
					}
				})
			}
	});
},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值