has.startCompass(Object object)
Starts listening for compass data.
Since: 1.0.4
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
|---|---|
| 12003701 | startCompass:fail. For details, see Sensor Error Codes. |
Example:
has.startCompass({
success: () => {
console.info('startCompass success');
},
fail: (err) => {
console.error('startCompass fail', err);
},
complete: (res) => {
console.info('startCompass complete', res);
}
}); has.stopCompass(Object object)
Stops listening for compass data.
Since: 1.0.4
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
|---|---|
| 12003801 | stopCompass:fail. For details, see Sensor Error Codes. |
Example:
has.stopCompass({
success: () => {
console.info('stopCompass success');
},
fail: (err) => {
console.error('stopCompass fail', err);
},
complete: (res) => {
console.info('stopCompass complete', res);
}
}); has.onCompassChange(function callback)
Listens for compass data change events.
Listening automatically runs at a rate of 5 times per second after this API is called and can be stopped by calling has.stopCompass.
Since: 1.0.4
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| callback | function | Yes | Callback for the compass change event. |
Return value of callback
| Parameter | Type | Description |
|---|---|---|
| direction | number | Direction in degrees. |
| accuracy | string | Accuracy. - high: high accuracy. - medium: medium accuracy. - low: low accuracy. - unreliable: unreliable value due to unknown reasons. |
Example:
has.onCompassChange(function(res) {
console.info('onCompassChange callback triggered', res);
}); has.offCompassChange(function callback)
Cancels listening for compass change events. If the callback parameter is left empty, listening will be disabled for all events.
Since: 1.0.4
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| callback | function | No | Callback for the compass change event. |
Example:
const onCompassChangeFn = function(res) {
console.info('onCompassChange callback triggered', res);
};
has.onCompassChange(onCompassChangeFn);
has.offCompassChange(onCompassChangeFn);