收藏
回答

微信小程序wx.getLocation之前好好的,突然今天就都失败了?

onLoad: function(options) {

    console.log(options)

    this.setData({

      realName: options.realName,

      carrierName: options.carrierName,

      toCompany: options.toCompany,

      id: options.id,

      companyCode: options.companyCode,

      alreadySign: options.driverCheckIn == 'Y' ? true : false,

    })


    let that = this

    wx.getSetting({

      success(res0) {

        console.log('查看是否吊起过授权', res0)

        // 查看是否吊起过授权

        if (!Object.keys(res0.authSetting).includes('scope.userLocation')) {

          that.getAddress()

          return

        }

        // 已经吊起过授权并且拒绝授权

        if (!res0.authSetting['scope.userLocation']) {

          wx.showModal({

            title: '您未开启地理位置授权',

            content: '为了给您提供更好的服务,请您授权地理位置,谢谢',

            success: res2 => {

              if (res2.confirm{

                wx.openSetting({

                  success(res3) {

                    console.log('吊起过授权---并且拒绝--重新设置授权',res3)

                    // 成功授权地理位置

                    if (res3.authSetting['scope.userLocation']) {

                      that.getAddress()

                    } else {

                      // 未授权地理位置,默认显示

                      console.log('重新授权---未允许,默认显示')

                      that.getAddress()

                    }

                  }

                })

              } else {

                console.log('拒绝授权地理位置,默认显示')

                that.getAddress()

              }

            }

          })

        } else {

          that.getAddress()

        }

      }

    })

  },

rad(d) {

    return d * Math.PI / 180.00

  },

  getAddress(){

    let that = this;

    wx.getLocation({

      type: 'wgs84',

      success(res) {

        let x = that.rad(res.longitude)

        let y = that.rad(res.latitude)

        that.setData({

          longitude: res.longitude,

          latitude: res.latitude

        })

        

        //  苏宝化坐标

        let x1 = that.rad(120.474476)

        let y1 = that.rad(31.410634)


        let w = x - x1

        let h = y - y1

        let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(w / 2), 2+ Math.cos(x* Math

          .cos(x1* Math.pow(Math.sin(h / 2), 2)))

        s = s * 6378137.0

        s = Math.round(s * 10000/ 10000


        console.log(s)

        if (s > 5000{

          that.setData({

            canSign: false,

            signAddressRange: s,

          })

        }else{

          that.setData({

            canSign: true,

            signAddressRange: s,

          })

        }

        that.driverCheckInDataHandler();

      },

      fail(res) {

        that.setData({

          canSign: false,

          signAddressRange: 'ssss',

        })

        console.log(res)

        wx.showModal({

          title: '提示',

          content: '获取定位失败',

          showCancel: false

        })

      },

      complete(res) {}

    })

  },

今天开始,进来页面wx.getLocation都会走到fail中


回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容