1004749546@qq.com 4 years ago
parent
commit
ebd281ca97
1 changed files with 55 additions and 15 deletions
  1. 55 15
      pages/index/index.vue

+ 55 - 15
pages/index/index.vue

@@ -171,21 +171,61 @@
 			// 获取当前位置
 			getCurPosition () {
 				let _this = this
-				uni.getLocation({
-					 type: 'wgs84', // 默认wgs84
-					 success: function(res) {
-					   console.log(res,'------')
-					   let lat = res.latitude
-					   let lng = res.longitude
-					   // 查询订单信息
-					   _this.getList(lat,lng)
-					 },
-					 fail: function(res) {
-						 console.log(res)
-						 // 查询订单信息
-						 _this.getList()
-					 }
-				});
+				uni.authorize({
+				    scope: 'scope.userLocation',
+				    success:()=> {
+						console.log(1111111111)
+				        uni.getLocation({
+				        	 type: 'wgs84', // 默认wgs84
+				        	 success: function(res) {
+				        	   console.log(res,'------')
+				        	   let lat = res.latitude
+				        	   let lng = res.longitude
+				        	   // 查询订单信息
+				        	   _this.getList(lat,lng)
+				        	 },
+				        	 fail: function(res) {
+				        		 console.log(res)
+				        		 // 查询订单信息
+				        		 _this.getList()
+				        	 }
+				        });
+				    },
+					fail() {
+						uni.getSetting({
+						   success(res) {
+						      console.log(res.authSetting,'gggggggggg')
+							  if(!res.authSetting['scope.userLocation']){
+								  uni.showModal({
+								    title: '提示',
+								    content: '无法展示用户距离,请开启定位功能!',
+								    success: (res)=> {
+								      if (res.confirm) {
+										uni.openSetting({
+										  success(res) {
+										    console.log(res.authSetting,'res.authSetting')
+										  },
+										  fail(err) {
+										  	console.log(err,'eeeeeeeee')
+										  }
+										})
+								      } else if (res.cancel) {
+								        console.log('用户点击取消');
+										_this.getList()
+								      }
+								    }
+								  });
+								 
+							  }
+						   },
+						   fail() {
+						   	_this.getList()
+						   }
+						})
+						
+					}
+				})
+				
 			},
 			// 待处理订单信息
 			getList (lat,lng) {