• 解决uni.getLocation用户端首次拒绝后,点第二次不会再调用的问题


    解决方案:给与用户手动指引开启手机定位
    效果(测试机为iphone11,机型不一样可能效果会有差别)
    1
    2
    3
    4

    <template>
    	<view class="detail-container">
    	   <view class="detail-map" @click="mapClick">
    								<text>地图</text>
    		</view>
    	</view>
    	</template>
    	<script>
    	export default {
    		data() {
    			return {}
    			   },
    			   methods: {
    			     mapClick() {
    			     //目的地的经纬度
    			     let item = {
    			     latitude:30.67914,
    			     longitude:103.960602
    			     }
    				let that = this;
    				uni.getLocation({
    					type: 'gcj02',
    					success: function(res) {
    						const latitude = Number(item.latitude);
    						const longitude = Number(item.longitude);
    						console.log("经度", latitude);
    						console.log("纬度", longitude);
    						uni.openLocation({
    							latitude,
    							longitude,
    							scale: 18
    						})
    					},fail(res) {
    					//用户拒绝后引导用户开启定位
    						that.getSetting(item);
    					}
    				})
    			},
    			//用户拒绝开启定位后-引导用户手动开启定位
    		   // 1.获取设置信息-用户权限列表
    		   			getSetting(item) {
    		    
    		   				uni.getSetting({
    		   					success: res => {
    		   						console.log('用户权限列表:', res.authSetting)
    		   						if (res.authSetting['scope.userLocation']) {
    		   							console.log('已授权userLocation')
    		   							// 选择位置信息
    		   			                this.mapClick(item)// 重新调取uni.getLocation
    		   						} else {
    		   							console.log('用户未授权userLocation')
    		   							//2.用户第一次进来发起授权
    		   							uni.showModal({
    		   								title: '提示',
    		   								content: '当前定位未开启,请点击确定手动开启定位',
    		   								duration: 3000,
    		   								success: (res) => {
    		   									if (res.confirm) {
    		        	                           this.openSetting()//点击确定引导客户开启定位
    		   									} else if (res.cancel) {
    		   										uni.showToast({
    		   											title: '你拒绝了授权,无法获取门店定位信息',
    		   											duration: 2000,
    		   											icon: "none"
    		   										});
    		   									}
    		   								}
    		   							});
    		   						}
    		   					}
    		   				})
    		   			},
    		    
    		   			// 4.打开设置
    		   			openSetting() {
    		   				uni.openSetting({
    		   					success: (res) => {
    		   						if (res.authSetting['scope.userLocation']) {
    		   							// 5.用户在设置中点击了允许,调用选择位置信息函数
    		   	                 	     this.mapClick(item)// 重新调取uni.getLocation
    		   						} else {
    		   							// 5.用户在设置中点击了不允许,展示拒绝授权信息
    		   							uni.showToast({
    		   								title: '你拒绝了授权,无法操作内容',
    		   								icon: "none",
    		   								duration: 3000,
    		   							})
    		   						}
    		   					},
    		   					fail: (err) => {
    		   						console.log("打开设置失败", err)
    		   					}
    		   				})
    		   			},
    			   }
    			   }
    	</script>		   
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97

    前端小白在此请各位大佬多多指教鸭!!!!记得给我点个赞哟!!!
    查看资料:添加链接描述

  • 相关阅读:
    【NestJS系列】连接数据库及优雅地处理响应
    javascript之dom详细笔记加练习
    InputAction的使用
    hive高级函数
    golang select 机制
    【Microelectronic Systems】
    ZJU Beamer学习手册(二)
    时序预测 | MATLAB实现SSA-GRU(麻雀算法优化门控循环单元)时间序列预测
    vuex的学习
    python类对象
  • 原文地址:https://blog.csdn.net/oneya1/article/details/126440820