天天看點

uniapp的h5和微信小程式判斷使用者裝置的位置服務是否開啟

//判斷使用者是否開啟定位-暫時不用
			checkOpenGPSServiceByAndroid() {
				let that = this
				// 1、判斷手機定位服務【GPS】 是否授權
				uni.getSystemInfo({
					success(res) {
						// console.log(res)
						let locationEnabled = res.locationEnabled; //判斷手機定位服務是否開啟
						let locationAuthorized = res.locationAuthorized; //判斷定位服務是否允許微信授權
						if (locationEnabled == false || locationAuthorized == false) {
							//手機定位服務(GPS)未授權
							uni.showModal({
								title: '提示',
								content: '請打開定位服務功能',
								showCancel: false, // 不顯示取消按鈕
								success() {
									uni.navigateBack({
										delta: 1, //傳回層數,2則上上頁
									})
								}
							})
						} else {
							//手機定位服務(GPS)已授權
							if (res.hostName == 'WeChat') {
								//2、判斷微信小程式是否授權位置資訊
								uni.getSetting({
									success(res) {
										let scopeUserLocation = res.authSetting["scope.userLocation"];
										if (scopeUserLocation) {
											// 微信小程式已授權位置資訊
											that.getCurrent()
										} else {
											// 微信小程式未授權位置資訊
											uni.showModal({
												title: '提示',
												content: '請允許使用位置資訊',
												showCancel: false, // 不顯示取消按鈕
												success() {
													uni.navigateBack({
														delta: 1, //傳回層數,2則上上頁
													})
												}
											})
										}
									},
									fail() {
										// 微信小程式未授權位置資訊
										uni.showModal({
											title: '提示',
											content: '擷取位置資訊失敗',
											showCancel: false, // 不顯示取消按鈕
											success() {
												uni.navigateBack({
													delta: 1, //傳回層數,2則上上頁
												})
											}
										})
									}
								});

							} else {
								that.getCurrent()
							}
						}
					},
					fail() {
						// 手機定位服務(GPS)未授權
						uni.showModal({
							title: '提示',
							content: '擷取位置資訊失敗',
							showCancel: false, // 不顯示取消按鈕
							success() {
								uni.navigateBack({
									delta: 1, //傳回層數,2則上上頁
								})
							}
						})
					}
				});
			},
           

        僅此記錄,以待後用。

上一篇: 元件屬性啊
下一篇: cpp的STL之map

繼續閱讀