// 獲取用戶的地理位置,
getLocation() {
? ? uni.getLocation({
? ? ? ? type: 'gcj02',
? ? ? ? altitude: true,
? ? ? ? success(res) {
? ? ? ? ? ? let latAndLon = {
? ? ? ? ? ? ? ? mylog: res.longitude,
? ? ? ? ? ? ? ? mylat: res.latitude
? ? ? ? ? ? }
? ? ? ? ? ? uni.setStorageSync('latAndLon', latAndLon)
? ? ? ? }
? ? })
},
? ? /*判斷是否已經(jīng)授權(quán) */
? ? getSetting() {
? ? ? ? const that = this
? ? ? ? uni.getSetting({
? ? ? ? ? ? success(res) {
? ? ? ? ? ? ? ? if (res.authSetting['scope.userLocation']) {
? ? ? ? ? ? ? ? ? ? that.getLocation()
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? that.getAuthorize()
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? })
? ? },
? ? ? ? // 自動授權(quán)
? ? ? ? getAuthorize() {
? ? ? ? ? ? let that = this
? ? ? ? ? ? uni.authorize({
? ? ? ? ? ? ? ? scope: 'scope.userLocation',
? ? ? ? ? ? ? ? success(res) {
? ? ? ? ? ? ? ? ? ? that.getLocation()
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? // 授權(quán)失敗
? ? ? ? ? ? ? ? fail(err) {
? ? ? ? ? ? ? ? ? ? uni.showModal({
? ? ? ? ? ? ? ? ? ? ? ? title: '提示',
? ? ? ? ? ? ? ? ? ? ? ? content: '請授權(quán)位置獲取附近的商家!',
? ? ? ? ? ? ? ? ? ? ? ? showCancel: false,
? ? ? ? ? ? ? ? ? ? ? ? confirmText: '確認授權(quán)',
? ? ? ? ? ? ? ? ? ? ? ? success() {
? ? ? ? ? ? ? ? ? ? ? ? ? ? uni.openSetting({
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? success(res) {},
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? fail(err) {}
? ? ? ? ? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? }
? ? ? ? ? ? })
? ? ? ? },