Getting Started
이 플러그인의 설치 단계와 전체 마크다운 가이드를 포함한 설정 지시서를 복사하세요.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-compass`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/compass/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
설치
설치 제목AI-Assisted Setup을 사용하여 플러그인을 설치할 수 있습니다. AI 도구에 Capgo 기능을 추가하려면 다음 명령어를 사용하세요:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins만약 Manual Setup을 선호한다면, 플러그인을 설치하기 위해 다음 명령어를 실행하고 아래에 플랫폼에 따라 설명된 지침을 따르세요:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-compass` plugin in my project.설치
bun add @capgo/capacitor-compassbunx cap syncimport { CapgoCompass } from '@capgo/capacitor-compass';API 개요
‘API 개요’ 제목의 섹션getCurrentHeading
현재 방향 얻기현재 방위각을 얻습니다. iOS에서는 방위각이 배경에서 업데이트되고 최신 값이 반환됩니다. Android에서는 방위각이 가속도계 및 자이로 센서를 사용하여 호출할 때 계산됩니다. 웹에서는 구현되지 않습니다.
import { CapgoCompass } from '@capgo/capacitor-compass';
const { value } = await CapgoCompass.getCurrentHeading();console.log('Compass heading:', value, 'degrees');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 updatesawait CapgoCompass.startListening({ minInterval: 50, // 50ms between events minHeadingChange: 1.0 // 1° minimum change});
CapgoCompass.addListener('headingChange', (event) => { console.log('Heading:', event.value);});stopListening
__CAPGO_KEEP_1____CAPGO_KEEP_2__
import { CapgoCompass } from '@capgo/capacitor-compass';
await CapgoCompass.stopListening();checkPermissions
__CAPGO_KEEP_3____CAPGO_KEEP_4__
import { CapgoCompass } from '@capgo/capacitor-compass';
const status = await CapgoCompass.checkPermissions();console.log('Compass permission:', status.compass);requestPermissions
__CAPGO_KEEP_5____CAPGO_KEEP_0__
import { CapgoCompass } from '@capgo/capacitor-compass';
const status = await CapgoCompass.requestPermissions();if (status.compass === 'granted') { // Can now use compass}watchAccuracy
__CAPGO_KEEP_0____CAPGO_KEEP_7__
import { CapgoCompass } from '@capgo/capacitor-compass';
// Start monitoring accuracyawait CapgoCompass.watchAccuracy();
// Listen for accuracy changes and implement custom UICapgoCompass.addListener('accuracyChange', (event) => { console.log('Accuracy changed to:', event.accuracy); if (event.accuracy < CompassAccuracy.MEDIUM) { // Show your custom calibration UI }});unwatchAccuracy
__CAPGO_KEEP_1____CAPGO_KEEP_2__
import { CapgoCompass } from '@capgo/capacitor-compass';
await CapgoCompass.unwatchAccuracy();getAccuracy
__CAPGO_KEEP_1____CAPGO_KEEP_3__
import { CapgoCompass } from '@capgo/capacitor-compass';
const { accuracy } = await CapgoCompass.getAccuracy();if (accuracy < CompassAccuracy.MEDIUM) { console.log('Compass needs calibration');}__CAPGO_KEEP_4__
__CAPGO_KEEP_5__CompassHeading
__CAPGO_KEEP_6____CAPGO_KEEP_7__
export interface CompassHeading { /** Compass heading in degrees (0-360) */ value: number;}ListeningOptions
ListeningOptionscompass를 사용하는 방식의 설정을 구성하는 옵션입니다.
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
HeadingChangeEvent헤딩이 변경된 이벤트의 데이터입니다.
export interface HeadingChangeEvent { /** Compass heading in degrees (0-360) */ value: number;}AccuracyChangeEvent
AccuracyChangeEvent정확도가 변경된 이벤트의 데이터입니다.
export interface AccuracyChangeEvent { /** Current accuracy level of the compass */ accuracy: CompassAccuracy;}PermissionStatus
PermissionStatuscompass 플러그인의 권한 상태입니다.
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
Compass Accuracycompass 정확도 상수.
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,}PermissionState
권한 상태compass 접근 권한 상태.
export type PermissionState = 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';진실의 근원
Section titled “진실의 근원”이 페이지는 플러그인의 src/definitions.ts업스트림에서 pubic API이 변경될 때 다시 싱크를 실행하세요.
Getting Started에서 계속
Section titled “Getting Started에서 계속”만약에 사용 중이라면 Getting Started API를 계획하고 API 연산을 위해 연결하세요. capgo/capacitor-compass를 사용하여 @capgo/capacitor-compass for the native capability in Using @capgo/capacitor-compass, API Overview에서 구현 세부 정보를 참조하세요. for the implementation detail in API Overview, 소개에서 구현 세부 정보를 참조하세요. __CAPGO_KEEP_0__ Keys API Keys에서 구현 세부 정보를 참조하세요. for the implementation detail in API Keys, and __CAPGO_KEEP_0__를 계획하고 __CAPGO_KEEP_0__ 연산을 위해 연결하세요. __CAPGO_KEEP_0__ 구현 세부 사항입니다.