__CAPGO_KEEP_0__

はじめに

GitHub

CapgoのAI-Assisted Setupを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを実行してください。

ターミナルウィンドウ
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Capgoのマーケティングウェブサイトのページ/エリア: Capgoマーケティングウェブサイトのページ/エリア。ロール: UIラベル。表示: ページagents/[slug].astro。メッセージキー`agents_page_copy_label` (Agents Page Copy Label)。

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-compass` plugin in my project.

次に、以下のプロンプトを使用してください。

ターミナルウィンドウ
bun add @capgo/capacitor-compass
bunx cap sync

インポート

インポート
import { CapgoCompass } from '@capgo/capacitor-compass';

APIの概要

APIの概要

getCurrentHeading

getCurrentHeading

現在のコンパス向きを取得します。 iOSでは、背景で向きが更新され、最新の値が返されます。 Androidでは、メソッドが呼び出されたときに加速度計と磁気センサを使用して向きが計算されます。 Webでは実装されていません。

import { CapgoCompass } from '@capgo/capacitor-compass';
const { value } = await CapgoCompass.getCurrentHeading();
console.log('Compass heading:', value, 'degrees');

startListening

startListening

コンパス向きの変化をイベントで受信するように開始します。 このメソッドを呼び出すと、コンパスセンサが開始され、'headingChange'イベントが発生します。

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

「stopListening」

コンパスヘッドの変更を停止する。

import { CapgoCompass } from '@capgo/capacitor-compass';
await CapgoCompass.stopListening();

checkPermissions

Copy to clipboard

コンテキスト: Capgo マーケティング ウェブサイト。役割: UI ラベル。表示場所: ページエージェント/[slug].astro。メッセージキー `agents_page_copy_label` (エージェント ページ コピー ラベル)。

import { CapgoCompass } from '@capgo/capacitor-compass';
const status = await CapgoCompass.checkPermissions();
console.log('Compass permission:', status.compass);

コンパスデータへのアクセス許可の現在の状態を確認します。

import { CapgoCompass } from '@capgo/capacitor-compass';
const status = await CapgoCompass.requestPermissions();
if (status.compass === 'granted') {
// Can now use compass
}

Android の場合、この機能は常に ‘許可’ を返します。なぜなら、許可が必要ないからです。

import { CapgoCompass, CompassAccuracy } from '@capgo/capacitor-compass';
// Start monitoring accuracy
await CapgoCompass.watchAccuracy();
// Listen for accuracy changes and implement custom UI
CapgoCompass.addListener('accuracyChange', (event) => {
console.log('Accuracy changed to:', event.accuracy);
if (event.accuracy < CompassAccuracy.MEDIUM) {
// Show your custom calibration UI
}
});

精度監視を停止する 精度の監視を停止します。

import { CapgoCompass } from '@capgo/capacitor-compass';
await CapgoCompass.unwatchAccuracy();

「getAccuracy」セクション

import { CapgoCompass, CompassAccuracy } from '@capgo/capacitor-compass';
const { accuracy } = await CapgoCompass.getAccuracy();
if (accuracy < CompassAccuracy.MEDIUM) {
console.log('Compass needs calibration');
}

現在のコンパス精度を取得する Android の場合、現在の磁気センサの精度を返します。 iOS と Web の場合、精度の監視が利用できないため、常に CompassAccuracy.UNKNOWN を返します。

型参照

「CompassHeading」セクション

export interface CompassHeading {
/** Compass heading in degrees (0-360) */
value: number;
}

コンパスを構成するためのオプション

export interface ListeningOptions {
/**
* Minimum interval between heading change events in milliseconds.
* Lower values = more frequent updates but higher CPU/battery usage.
*
* @default 100
* @since 8.1.4
*/
minInterval?: number;
/**
* Minimum heading change in degrees required to trigger an event.
* Lower values = more sensitive but more events.
* Handles wraparound (e.g., 359° to 1° = 2° change).
*
* @default 2.0
* @since 8.1.4
*/
minHeadingChange?: number;
}

HeadingChangeEvent

コピー

ヘッディング変更イベント

export interface HeadingChangeEvent {
/** Compass heading in degrees (0-360) */
value: number;
}

精度変更イベント

export interface AccuracyChangeEvent {
/** Current accuracy level of the compass */
accuracy: CompassAccuracy;
}

パーミッションステータス

export interface PermissionStatus {
/**
* Permission state for accessing compass/location data.
* On iOS, this requires location permission to access heading.
* On Android, no special permissions are required for compass sensors.
*
* @since 7.0.0
*/
compass: PermissionState;
}

CompassAccuracy

コンパス精度

コンパス精度レベル定数。

export enum CompassAccuracy {
/** High accuracy - approximates to less than 5 degrees of error */
HIGH = 3,
/** Medium accuracy - approximates to less than 10 degrees of error */
MEDIUM = 2,
/** Low accuracy - approximates to less than 15 degrees of error */
LOW = 1,
/** Unreliable accuracy - approximates to more than 15 degrees of error */
UNRELIABLE = 0,
/** Unknown accuracy value */
UNKNOWN = -1,
}

コンパスへのアクセス用パーミッション状態

export type PermissionState = 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';

ソースオブトゥース

ソースオブトゥース

このページはプラグインの src/definitions.ts再同期を実行してください。パブリックAPIがアップストリームで変更されたときに。

続けてGetting Started

続けてGetting Started

あなたが スタートガイド ダッシュボードとAPIの計画と実行に必要なものは Using @capgo/capacitor-compass Using @capgo/capacitor-compassのネイティブ機能 APIの概要 APIの概要の実装 導入 導入の実装 APIのキー APIのキーの実装 デバイス デバイスの実装