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.
설치
설치bun add @capgo/capacitor-compassbunx cap syncImport
Importimport { 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 updatesawait 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
자세한 데이터 접근 권한의 현재 상태를 확인합니다.
iOS에서는 위치 권한 상태를 확인합니다.
Android에서는 항상 'granted'을 반환합니다. (권한이 필요하지 않습니다.)클립보드에 복사
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
watchAccuracyAndroid 기기에서는 자이로 센서 정확도와 정확도 변경 이벤트를 모니터링합니다. 개발자는 이러한 이벤트를 듣고 캘리브레이션 프롬프트 UI를 구현할 수 있습니다. iOS 및 Web에서는 자이로 센서 정확도 모니터링이 지원되지 않습니다.
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
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');}자이로 센서 방향
CompassHeadingCompassHeading
Copy to clipboard자이로 방향값이 포함된 결과.
export interface CompassHeading { /** Compass heading in degrees (0-360) */ value: number;}ListeningOptions
“ListeningOptions” 섹션자이로 방향 감지 동작을 구성하는 옵션.
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” 섹션__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;}CompassAccuracy
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';진실의 근거
Compass 정확도 수준 상수이 페이지는 플러그인의 src/definitions.tsAPI의 공개 버전이 업스트림에서 변경되면 다시 싱크를 실행하세요.
시작부터 계속하기
시작부터 계속하기 섹션Capgo를 사용 중이라면 시작하기 API 대시보드와 연산을 계획하기 위해, API와 연결하세요. capgo-compass를 사용하여 @capgo/capacitor-compass capgo-compass를 사용하여 @capgo/capacitor-compass의 네이티브 기능 API 개요 API 개요의 구현 세부 정보 소개 소개의 구현 세부 정보 API 키 구현 세부 사항은 API 키에 있습니다. 기기 구현 세부 사항은 기기에 있습니다.