05 手机罗盘模块 - MiEcosystem/miot-plugin-sdk GitHub Wiki
手机的罗盘
Export: public
Doc_name: 手机罗盘模块
Doc_index: 5
Doc_directory: system
Example
import {System} from "miot"
import {CompassChangeEvent} from "miot"
...
System.compass.startCompass(//interval).then(() => {
alert(`startCompass: ${ JSON.stringify(res) }`);
})
...
System.compass.stopCompass().then(() => {})
...
-
miot/system
-
static
-
.CompassChangeEvent ⇒
number
-
.CompassChangeEvent ⇒
-
inner
-
~ICompass
-
.startCompass(interval) ⇒
[ 'Promise' ].<json>
-
.stopCompass() ⇒
[ 'Promise' ].<json>
-
.startCompass(interval) ⇒
-
~ICompass
-
static
监听罗盘数据变化事件。频率:5 次/秒,接口调用后会自动开始监听,可使用 wx.stopCompass 停止监听。
Kind: static constant of miot/system
Returns: number
- direction 面对的方向度数
Since: 10043
Example
CompassChangeEvent.onCompassChange.addListener((result) => {
console.log(result);
});
Kind: inner interface of miot/system
-
~ICompass
-
.startCompass(interval) ⇒
[ 'Promise' ].<json>
-
.stopCompass() ⇒
[ 'Promise' ].<json>
-
.startCompass(interval) ⇒
开始监听罗盘数据
Kind: instance method of ICompass
Returns: [ 'Promise' ].<json>
- 成功时:{code:0,message:'success'}
Since: 10043
Param | Type | Description |
---|---|---|
interval | string |
监听罗盘数据回调函数的执行频率。其合法值如下: game 适用于更新游戏的回调频率,在 20ms/次 左右; ui 适用于更新 UI 的回调频率,在 60ms/次 左右; normal 普通的回调频率,在 200ms/次 左右。 |
Example
System.compass.startCompass(interval.c).then((res) => {
alert(`startCompass: ${ JSON.stringify(res) }`);
}).catch((error) => {
console.log(error);
});
停止监听罗盘数据
Kind: instance method of ICompass
Returns: [ 'Promise' ].<json>
- 成功时:{code:0,message:'success'}
Since: 10043
Example
System.compass.stopCompass().then((res) => {
alert(`stopCompass: ${ JSON.stringify(res) }`);
}).catch((error) => {
console.log(error);
});
}