---
name: "onCompassChange"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.3.2" }
  - { name: "@ray-js/ray", version: "0.3.23" }
platform:
  - "iOS"
  - "Android"
async: true
---

## onCompassChange

> [VERSION] BaseKit >= 2.3.2 | @ray-js/ray >= 0.3.23

> [PLATFORM] iOS, Android

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

### Description

Listen for compass data change events

### Parameters

`(listener: Function)`

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

##### 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 (platform differences between iOS and Android lead to different return values) Android:   high  High accuracy   medium  Medium accuracy   low  Low accuracy   no-contact  Unreliable; sensor disconnected   unreliable  Unreliable; reason unknown   unknow ${value}  Unknown accuracy enum value; the accuracy value returned by Android is not a standard enum value iOS:   Accuracy value of type double |


### Examples

#### Demo

```tsx
import { onCompassChange, startCompass } from '@ray-js/ray'

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