收藏
回答

wx.onLocationChange获取不到speed数据,问题出在哪里?

遇到的问题:开发一个上报地理位置的小程序,打包成体验版在ios下测试;调用startLocationUpdateBackground接口后,在onLocationChange中可以正常获得数据,除了speed一直返回-1。有哪位大神知道问题在哪里吗?


var that=this;


wx.startLocationUpdateBackground({

  success: function () {
    console.info("持续定位初始化成功");
    wx.onLocationChange(function (res) {
      console.info('[' + util.formatTime(new Date()) + ']位置改变:', res);
      that.setData({
        currentLongitude: res.longitude,
        currentLatitude: res.latitude,
        speed: res.speed,
        altitude: res.altitude
      });
      that.doReport();          
    })
  },
  fail: function () {
    console.info("持续定位初始化失败");
    wx.getSetting({
      success(res) {
        if (res.authSetting["scope.userLocationBackground"] != true ){
          wx.showModal({
            title: '提示',
            content: '您需要允许(使用小程序期间和离开小程序后)选项',
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后
                wx.openSetting({
                  success(res) {
                    that.doMain();
                  },
                  fail: function () {
                    console.info("打开设置失败")
                  }
                });
              } else { //这里是点击了取消以后
                //console.log('用户点击取消')
              }
            }
          })
        } else { console.info("未知错误"); }
      }
    })       
  }
})



最后一次编辑于  09-05
回答关注问题邀请回答
收藏

2 个回答

问题标签