English
listen to the compass data at a frequency of 5 times/second. The listening to will automatically start after calling the interface. You can use uni.offCompassChange
to cancel the listening to.
CALLBACK return parameter
Parameter | Type | Instruction |
---|---|---|
direction | Number | Degree of the direction facing |
Tips
Example
const callback = function (res) {
console.log(res.direction);
}
uni.onCompassChange(callback);
Cancel listening to compass data.
Example
const callback = function (res) {
console.log(res.direction);
}
uni.onCompassChange(callback);
// Pass in the same function as onCompassChange
uni.offCompassChange(callback);
Tips
CALLBACK
is the CALLBACK
passed in when calling uni.onCompassChange
Start listening to compass data.
OBJECT parameter description
Parameter name | Type | Required | Instruction |
---|---|---|---|
success | Function | No | Callback for successful interface calling |
fail | Function | No | Callback function for failed interface calling |
complete | Function | No | Callback function for closed interface calling (available both for successful and failed calling) |
Example
uni.startCompass();
Stop listening to compass data.
OBJECT parameter description
Parameter name | Type | Required | Instruction |
---|---|---|---|
success | Function | No | Callback for successful interface calling |
fail | Function | No | Callback function for failed interface calling |
complete | Function | No | Callback function for closed interface calling (available both for successful and failed calling) |
Example
uni.stopCompass();