监听罗盘数据,频率:5次/秒,接口调用后会自动开始监听,可使用wx.stopcompass
停止监听。
callback返回参数:
参数 | 类型 | 说明 |
---|---|---|
direction | number | 面对的方向度数 |
示例代码:
wx.oncompasschange(function (res) {
console.log(res.direction)
})
基础库 1.1.0 开始支持,低版本需做兼容处理
开始监听罗盘数据。
object参数说明:
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
success | function | 否 | 接口调用成功的回调函数 |
fail | function | 否 | 接口调用失败的回调函数 |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
示例代码:
wx.startcompass()
基础库 1.1.0 开始支持,低版本需做兼容处理
停止监听罗盘数据。
object参数说明:
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
success | function | 否 | 接口调用成功的回调函数 |
fail | function | 否 | 接口调用失败的回调函数 |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
示例代码:
wx.stopcompass()