收藏
回答

getLocation一直报fail,但是无fail数据?

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

微信开发者工具是1.03.2006090

手机型号是OPPO PCLM10

Android版本10

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

3 个回答

  • 疯狂的小辣椒
    疯狂的小辣椒
    2020-07-22

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

    2020-07-22
    有用
    回复 2
    • 乌贼熊
      乌贼熊
      2020-07-22
      我发现了问题,我修改了一下代码,发现fail信息是
      {errMsg: "getLocation:fail:invalid data", errCode: -1}
      errCode: -1
      errMsg: "getLocation:fail:invalid data"
      __proto__: Object
      位置服务已经打开,请问这是什么意思
      2020-07-22
      回复
    • 乌贼熊
      乌贼熊
      2020-07-22
      您好,我已经解决了,原因是调用getLocation时自动生成的type:'type',要手动更改'type'的内容为wgs84。至于没打印res是我把log写错地方了
      2020-07-22
      回复
  • 森林之王
    森林之王
    发表于移动端
    2020-07-22
    q
    2020-07-22
    有用
    回复
  • 乌贼熊
    乌贼熊
    2020-07-22
    以下是这部分代码
    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("获取定位失败")
                }
               })
            }
          }
        })
        
      },
    
    2020-07-22
    有用
    回复
登录 后发表内容
问题标签