Skip to content

@capgo/capacitor-compass

Capacitor Compass Plugin interface for reading device compass heading.

Capacitor Compass Plugin interface for reading device compass heading.

  • getCurrentHeading - Get the current compass heading in degrees. On iOS, the heading is updated in the background, and the latest value is returned. On Android, the heading is calculated when the method is called using accelerometer and magnetometer sensors. Not implemented on Web.
  • startListening - Start listening for compass heading changes via events. This starts the compass sensors and emits ‘headingChange’ events.
  • stopListening - Stop listening for compass heading changes. This stops the compass sensors and stops emitting events.
  • checkPermissions - Check the current permission status for accessing compass data. On iOS, this checks location permission status. On Android, this always returns ‘granted’ as no permissions are required.
MethodDescription
getCurrentHeadingGet the current compass heading in degrees. On iOS, the heading is updated in the background, and the latest value is returned. On Android, the heading is calculated when the method is called using accelerometer and magnetometer sensors. Not implemented on Web.
getPluginVersionGet the native Capacitor plugin version.
startListeningStart listening for compass heading changes via events. This starts the compass sensors and emits ‘headingChange’ events.
stopListeningStop listening for compass heading changes. This stops the compass sensors and stops emitting events.
addListenerAdd a listener for compass heading change events.
addListenerAdd a listener for compass accuracy change events. Only supported on Android. On iOS and Web, this will never emit events.
removeAllListenersRemove all listeners for this plugin.
checkPermissionsCheck the current permission status for accessing compass data. On iOS, this checks location permission status. On Android, this always returns ‘granted’ as no permissions are required.
requestPermissionsRequest permission to access compass data. On iOS, this requests location permission (required for heading data). On Android, this resolves immediately as no permissions are required.
watchAccuracyStart monitoring compass accuracy. On Android, this monitors the magnetometer accuracy and emits accuracyChange events. Developers can listen to these events and implement their own UI for calibration prompts. On iOS and Web, this method does nothing as compass accuracy monitoring is not available.
unwatchAccuracyStop monitoring compass accuracy. This stops the accuracy monitoring.
getAccuracyGet the current compass accuracy level. On Android, returns the current magnetometer sensor accuracy. On iOS and Web, always returns CompassAccuracy.UNKNOWN as accuracy monitoring is not available.

This reference is synced from src/definitions.ts in capacitor-compass.