• 小程序判断手机位置是否打开


    // 获取当前地地址
        async getLocation() {
          let self = this
          let result = null
          try {
            const resultLocation = await wepy.getLocation()
            result = await this.geocoder(resultLocation)
          } catch (e) {
            wx.getSetting({
              success: function (res) {
                console.log('getSetting...', res)
                let statu = res.authSetting
                if (!statu['scope.userLocation']) {
                  wx.showModal({
                    title: '是否授权当前位置',
                    content: '需要获取您的地理位置,请确认授权,否则将无法获得优惠券',
                    success: function (tip) {
                      if (tip.confirm) {
                        wx.openSetting({
                          success: function (data) {
                            console.log('openSetting...', data)
                            if (data.authSetting['scope.userLocation'] === true) {
                              wepy.showToast({
                                title: '授权成功',
                                icon: 'success',
                                duration: 1000
                              })
                              // 授权成功之后,再调用chooseLocation选择地方
                              wepy.getLocation({
                                success(res) {
                                  self.geocoder(res)
                                }
                              })
                            } else {
                              // 开关关闭,提示无法拿到位置权限
                              wx.showModal({
                                title: '提示',
                                content: '无法使用定位权限',
                                confirmText: '太遗憾了',
                                showCancel: false
                              })
                            }
                          },
                          fail: function(res) {
                            console.log('openSetting.failed' + res)
                          }
                        })
                      }
                      if (tip.cancel) {
                        wx.showToast({
                          title: '定位失败',
                          icon: 'none',
                          duration: 1000
                        })
                      }
                    }
                  })
                } else {
                  wepy.showModal({
                    title: '定位服务已关闭',
                    content: '请在“设置”中打开定位服务,以便精准定位获取更多优惠消息!'
                  })
                }
              },
              fail: function (res) {
                console.log(res)
                wepy.showToast({
                  title: '调用授权窗口失败',
                  icon: 'success',
                  duration: 1000
                })
              }
            })
          }
          return result
        }
  • 相关阅读:
    读《大道至简—编程的精义》有感
    c++ 指针做为参数和返回值
    c++ 函数
    c++ 分配与释放内存
    c++ 以多维数组的形式访问动态内存
    c++ 动态数组,指针与动态内存分配
    c++ 指针访问数组
    c++ 常量指针
    c++ 指针
    c++ 字符串转换
  • 原文地址:https://www.cnblogs.com/fms-3/p/11857259.html
Copyright © 2020-2023  润新知