내용으로 건너뛰기

Getting Started

GitHub

Capgo의 AI-Assisted Setup을 사용하여 플러그인을 설치할 수 있습니다. AI 도구에 Capgo 기능을 추가하려면 다음 명령어를 사용하세요:

터미널 창
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

다음 명령어를 사용하세요:

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

만약 Manual Setup을 선호한다면, 플러그인을 설치하기 위해 다음 명령어를 실행하고 아래의 플랫폼별 지침을 따르세요:

터미널 창
bun add @capgo/capacitor-compass
bunx cap sync
import { CapgoCompass } from '@capgo/capacitor-compass';

getCurrentHeading

getCurrentHeading 섹션

현재 지구磁気의 방향을 얻습니다. iOS에서는 지구磁기 방향이 자동으로 업데이트되고, 최신 값을 반환합니다. Android에서는 메서드가 호출될 때 가속도계 및 자이로 센서를 사용하여 지구磁기 방향을 계산합니다. 웹에서는 구현되지 않았습니다.

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);
});

compass 방향 변경을 감지하는 것을 중단합니다. 이것은 compass 센서를 중단하고 이벤트를 중단합니다.

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

compass 데이터에 대한 현재 권한 상태를 확인합니다. iOS에서 이 메소드는 위치 권한 상태를 확인합니다. Android에서 이 메소드는 항상 '허용'을 반환합니다. 왜냐하면 권한이 필요하지 않기 때문입니다.

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

compass 데이터에 대한 권한을 요청합니다. iOS에서 이 메소드는 위치 권한을 요청합니다. (헤딩 데이터를 위해 필요합니다). Android에서 이 메소드는 즉시 해결됩니다. 왜냐하면 권한이 필요하지 않기 때문입니다.

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

compass 정확성을 모니터링합니다. Android에서 이 메소드는 자이로 센서 정확성을 모니터링하고 정확도 변경 이벤트를 발생시킵니다. 개발자는 이 이벤트를 듣고 자이로 센서의 정확도에 대한 사용자 인터페이스를 구현할 수 있습니다. iOS와 Web에서 이 메소드는 아무런 동작도 하지 않습니다. 왜냐하면 compass 정확도 모니터링이 지원되지 않기 때문입니다.

import { CapgoCompass } 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
}
});

unwatchAccuracy

unwatchAccuracy

지자기 센서 정확도 모니터링 중지. 이것은 정확도 모니터링을 중지합니다.

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

getAccuracy

getAccuracy

현재 지자기 센서 정확도 수준을 가져옵니다. 안드로이드에서는 현재 자이로 센서 정확도를 반환합니다. iOS와 Web에서는 항상 CompassAccuracy.UNKNOWN을 반환합니다.

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

타입 참조

CompassHeading

복사

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

ListeningOptions

ListeningOptions

compass 사용을 위한 옵션

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

PermissionStatus

compass 플러그인의 권한 상태

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 정확도

Compass 정확도 수준 상수.

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';

이 페이지는 플러그인의 src/definitions.ts공개 API이 업스트림에서 변경될 때 다시 싱크를 실행하세요.

이 기능을 사용 중이라면 Getting Started 대시보드와 API 기능을 계획하고 운영하기 위해 Using @capgo/capacitor-compass Using @capgo/capacitor-compass API 개요 API 개요 소개 소개 API 키 API 키 장치 장치에 대한 구현 세부 정보.