zoukankan      html  css  js  c++  java
  • 小程序判断手机位置是否打开

    // 获取当前地地址
        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
        }
  • 相关阅读:
    2016"百度之星"
    codeforces 55 div2 C.Title 模拟
    codeforces 98 div2 C.History 水题
    codeforces 97 div2 C.Replacement 水题
    codeforces 200 div2 C. Rational Resistance 思路题
    bzoj 2226 LCMSum 欧拉函数
    hdu 1163 九余数定理
    51nod 1225 余数的和 数学
    bzoj 2818 gcd 线性欧拉函数
    Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学
  • 原文地址:https://www.cnblogs.com/fms-3/p/11857259.html
Copyright © 2011-2022 走看看