내용으로 건너뛰기

Getting Started

설치

설치
터미널 창
bun add @capgo/capacitor-compass
bunx cap sync

Import

Import
import { CapgoCompass } from '@capgo/capacitor-compass';

API 개요

API 개요

getCurrentHeading

__getCurrentHeading__

__getCurrentHeading__: 현재 지구 자기장 방향을 도 단위로 반환합니다. iOS에서는 백그라운드에서 지구 자기장 방향을 업데이트하고, 최신 값을 반환합니다. Android에서는 __getCurrentHeading__ 메서드가 호출될 때 가속도계 및 자기장 센서를 사용하여 지구 자기장 방향을 계산합니다. 웹에서는 구현되지 않았습니다.

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

클립보드에 복사

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

requestPermissions

클립보드에 복사

startListening

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

watchAccuracy

watchAccuracy

Android 기기에서는 자이로 센서 정확도와 정확도 변경 이벤트를 모니터링합니다. 개발자는 이러한 이벤트를 듣고 캘리브레이션 프롬프트 UI를 구현할 수 있습니다. iOS 및 Web에서는 자이로 센서 정확도 모니터링이 지원되지 않습니다.

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

현재 자이로 센서 정확도 레벨을 반환합니다. Android 기기에서는 현재 자이로 센서 정확도를 반환하고 iOS 및 Web에서는 항상 자이로 센서 정확도 UNKNOWN을 반환합니다.

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

자이로 센서 방향

CompassHeading

CompassHeading

Copy to clipboard

자이로 방향값이 포함된 결과.

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

자이로 방향 변경 이벤트 데이터.

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

정확도 변경 이벤트 데이터.

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

__CAPGO_KEEP_0__의 권한 상태.

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

복사

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.tsAPI의 공개 버전이 업스트림에서 변경되면 다시 싱크를 실행하세요.

시작부터 계속하기

시작부터 계속하기 섹션

Capgo를 사용 중이라면 시작하기 API 대시보드와 연산을 계획하기 위해, API와 연결하세요. capgo-compass를 사용하여 @capgo/capacitor-compass capgo-compass를 사용하여 @capgo/capacitor-compass의 네이티브 기능 API 개요 API 개요의 구현 세부 정보 소개 소개의 구현 세부 정보 API 키 구현 세부 사항은 API 키에 있습니다. 기기 구현 세부 사항은 기기에 있습니다.