赛捷软件论坛's Archiver

vicky.yu 发表于 2026-6-9 10:42

微信小程序API-设备-罗盘

wx.onCompassChange(CALLBACK)
监听罗盘数据,频率:5次/秒,接口调用后会自动开始监听,可使用wx.stopCompass停止监听。
CALLBACK返回参数:

参数        类型        说明
direction        Number        面对的方向度数
示例代码:

wx.onCompassChange(function (res) {
  console.log(res.direction)
})

wx.startCompass(OBJECT)
基础库 1.1.0 开始支持,低版本需做兼容处理

开始监听罗盘数据。

OBJECT参数说明:

参数        类型        必填        说明
success        Function        否        接口调用成功的回调函数
fail        Function        否        接口调用失败的回调函数
complete        Function        否        接口调用结束的回调函数(调用成功、失败都会执行)
示例代码:

wx.startCompass()
wx.stopCompass(OBJECT)
基础库 1.1.0 开始支持,低版本需做兼容处理

停止监听罗盘数据。

OBJECT参数说明:

参数        类型        必填        说明
success        Function        否        接口调用成功的回调函数
fail        Function        否        接口调用失败的回调函数
complete        Function        否        接口调用结束的回调函数(调用成功、失败都会执行)
示例代码:

wx.stopCompass()
wx.offCompassChange(function callback)
基础库 2.9.3 开始支持,低版本需做兼容处理
取消监听罗盘数据变化事件,参数为空,则取消所有的事件监听。

参数
function callback
罗盘数据变化事件的回调函数

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.