Guide
__CAPGO_KEEP_0__ についてのチュートリアル
@capgo/capacitor-compass を使用してコンパスを読み取ります。
Capacitor コンパス プラグインのインターフェイスで、デバイスのコンパスヘッドを読み取ります。
Install
bun add @capgo/capacitor-compass
bunx cap sync
What This Plugin Exposes
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.
Example Usage
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.
import { CapgoCompass } from '@capgo/capacitor-compass';
const { value } = await CapgoCompass.getCurrentHeading();
console.log('Compass heading:', value, 'degrees');
startListening
Start listening for compass heading changes via events. This starts the compass sensors and emits 'headingChange' events.
import { CapgoCompass } from '@capgo/capacitor-compass';
// With default throttling (100ms interval, 2° minimum change)
await CapgoCompass.startListening();
// With custom throttling for high-frequency updates
await CapgoCompass.startListening({
minInterval: 50, // 50ms between events
minHeadingChange: 1.0 // 1° minimum change
});
CapgoCompass.addListener('headingChange', (event) => {
console.log('Heading:', event.value);
});
stopListening
Stop listening for compass heading changes. This stops the compass sensors and stops emitting events.
import { CapgoCompass } from '@capgo/capacitor-compass';
await CapgoCompass.stopListening();
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.
import { CapgoCompass } from '@capgo/capacitor-compass';
const status = await CapgoCompass.checkPermissions();
console.log('Compass permission:', status.compass);
Full Reference
- GitHub: https://github.com/Cap-go/capacitor-
- ドキュメント: /docs/plugins/__CAPGO_KEEP_1__/
Keep going from Using @capgo/capacitor-compass
Capacitor Compassを使用している場合 Using @capgo/capacitor-compass to plan dashboard and API operations, connect it with @capgo/capacitor-compass for the implementation detail in @capgo/capacitor-compass, Capacitor Compassの概要 __CAPGO_KEEP_0__ API Overview 実装詳細については API の概要を参照してください。 概要 実装詳細については Introduction を参照してください。 API Keys 実装詳細については API のキーの概要を参照してください。