my.stopCompass
The my.stopCompass JSAPI is called by mini program developers to stop compass monitoring.
Parameters
Parameter | Data type | Required | Description |
success | Function | No | A callback that is executed when the JSAPI call is successful. |
fail | Function | No | A callback that is executed when the JSAPI call fails. When executed, it receives an |
complete | Function | No | A callback that is executed when the JSAPI call completes, regardless of success or failure. |
err
object
Parameter | Data type | Required | Description |
error | Number | Yes | An error code that represents the specific error encountered. |
errorMessage | String | Yes | An error message that describes the corresponding error code. |
Sample code
copy
Page({
// Define a callback to handle compass data
callback(res) {
console.log(res.direction);
},
onReady() {
// Start compass monitoring
my.startCompass();
// Register a callback for compass updates
my.onCompassChange(this.callback);
},
onUnload() {
// Stop compass monitoring
my.stopCompass({
success: () => {
// Remove the registered callback
my.offCompassChange(this.callback);
},
fail(err) {
console.log(err)
}
});
}
})