getLocation一直报fail,但是无fail数据?
发布于 6 年前 作者 duanxiuying 3682 次浏览 来自 官方Issues

自己电脑上能获取到,但是后来真机测试就不行,把项目给同学跑也不行。

微信开发者工具是1.03.2006090

手机型号是OPPO PCLM10

Android版本10


3 回复

你好,确认开启位置服务了么?

以下是这部分代码
getLocation:function(){
    var that = this
    wx.getSetting({
      withSubscriptionstrue,
      success(res){
        console.log("获取设置成功")
        var status = res.authSetting["scope.userLocation"]
        if(!status){
          console.log("位置权限为false")
          wx.authorize({
            scope'scope.userLocation',
            success(res){
              console.log("位置授权成功")
              wx.getLocation({  //微信自带获取位置
                success:function (res{
                  var longitude = res.longitude
                  var latitude = res.latitude
                  that.setData({
                    ["location.latitude"]:latitude,
                    ["location.longitude"]:longitude
                  })
                  that.localCity(longitude, latitude)
                },
                fail:function(res){
                  console.log("获取定位失败")
                  console.log(res)
                }
               })
            }
          })
        }
        else{
          console.log("位置权限为true")
          wx.getLocation({  //微信自带获取位置
            altitude'altitude',
            highAccuracyExpireTime0,
            isHighAccuracytrue,
            type'type',
            success:function (res{
              var longitude = res.longitude
              var latitude = res.latitude
              that.setData({
                ["location.latitude"]:latitude,
                ["location.longitude"]:longitude
              })
              that.localCity(longitude, latitude)
            },
            fail:function(res){
              console.log("获取定位失败")
            }
           })
        }
      }
    })
    
  },
回到顶部