---
name: "onCompassChange"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.3.2" }
platform:
  - "iOS"
  - "Android"
async: true
---

## onCompassChange

> [VERSION] BaseKit >= 2.3.2

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Listen for compass data change event

### Parameters

`(listener: Function)`

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `listener` | `(params: Object) => void` | Yes | - | Event listener callback function |

##### onCompassChange.listener(params) properties

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `direction` | `number` | Yes | - | `2.3.2` | Heading (degrees) |
| `accuracy` | `string` | Yes | - | `2.3.2` | Accuracy (returns differ between iOS and Android due to platform differences) Android:   high High accuracy   medium    Medium accuracy   low    Low accuracy   no-contact    Unreliable, sensor lost contact   unreliable    Unreliable, reason unknown   unknow ${value}    Unknown accuracy enum value; the accuracy value returned by this Android system is not a standard accuracy enum iOS:   double-type accuracy |


### Examples

```tsx
// Listen for compass data changes: register onCompassChange first, then startCompass to enable the sensor; heading data will be returned via callbacks
ty.onCompassChange(e => {
  console.log("Compass direction:", e.direction, "Accuracy:", e.accuracy);
});
ty.startCompass({
  success: () => console.log("Started listening to compass"),
  fail: error => console.error(error),
});
```
