my.onCompassChange(function callback)
Note:
- This interface is supported since basic library version 1.9.0. Compatibility processing is required for earlier versions. See Mini Program base library to learn more.
- This interface is only supported in mPaaS 10.1.60 and later versions.
Use this API to listen to the compass data. After the interface is called, the listening is automatically started. The callback interval is 500ms. You can use my.offCompassChange
to stop listening.
Parameters
Parameter | Type | Description |
---|---|---|
function | callback | Callback function for the compass data change events. |
Callback return value
Parameter | Type | Description |
---|---|---|
direction | Number | The degree between the direction that you are facing and geographical north: [0,360) |
Sample code
my.onCompassChange(function (res) {
console.log(res.direction)
})
my.offCompassChange()
Note:
- This interface is supported since basic library version 1.9.0. Compatibility processing is required for earlier versions. See Mini Program base library to learn more.
- This interface is only supported in mPaaS 10.1.60 and later versions.
Use this API to unlisten to the compass data.
Sample code
my.offCompassChange()
Whether to pass callback value or not
If the callback value is not passed, the callbacks of all events will be removed. The sample code is as follows:
my.offCompassChange();
If the callback value is passed, only the corresponding callback is removed. The sample code is as follows:
my.offCompassChange(this.callback);