메인 콘텐츠로 바로 가기
플러그인으로 돌아가기
@capgo/capacitor-배경위치추적
튜토리얼
@capgo/capacitor-배경위치추적

배경위치추적

__CAPGO_KEEP_0__ 위치 추적을 위한 정확한 배경 위치 추적, native iOS 및 Android geofencing 및 전환 웹 훅

설명서

__CAPGO_KEEP_0__ 배경 위치 추적에 대한 튜토리얼

@capgo/background-geolocation 사용

Capacitor 앱에 대한 정확한 배경 위치 추적 및 native iOS 및 Android geofencing. Capacitor 위치 업데이트 스트리밍, circular 지역 모니터링 및 JavaScript 또는 백엔드에 대한 geofence enter/exit 전환을 사용하여.

__CAPGO_KEEP_0__ 설치

bun add @capgo/background-geolocation
bunx cap sync

이 플러그인은 노출합니다.

  • start - 정확한 전면 또는 배경 위치 업데이트 스트림.
  • stop - 활성 위치 추적 중지.
  • openSettings - 사용자가 위치 권한을 수정해야 할 때 native 설정 열기.
  • setPlannedRoute - 사용자가 계획된 경로를 떠났을 때 native 사운드 재생.
  • setupGeofencing - native 지오펜스 기본값 구성 및 선택적 전환 웹 훅 전달.
  • addGeofence - iOS 또는 Android 지오펜스圆형 영역 모니터링.
  • removeGeofence / removeAllGeofences - 등록된 영역 중 하나 또는 모두 중지 모니터링.
  • getMonitoredGeofences - 모니터링 중인 영역 식별자 목록.
  • geofenceTransition listener - 앱이 활성화된 동안 입장 및 출입 이벤트 수신.
  • geofenceError listener - native 모니터링 오류를 전환 이벤트와 별도로 처리.

예시 사용법

start

To start listening for changes in the device's location, call this method. A Promise is returned to indicate that it finished the call. The callback will be called every time a new location is available, or if there was an error when calling this method. Don't rely on promise rejection for this.

import { BackgroundGeolocation } from '@capgo/background-geolocation';

await BackgroundGeolocation.start(
  {
    backgroundMessage: "App is using your location in the background",
    backgroundTitle: "Location Service",
    requestPermissions: true,
    stale: false,
    distanceFilter: 10
  },
  (location, error) => {
    if (error) {
      console.error('Location error:', error);
      return;
    }
    if (location) {
      console.log('New location:', location.latitude, location.longitude);
    }
  }
);

stop

위치 업데이트를 중지합니다.

import { BackgroundGeolocation } from '@capgo/background-geolocation';

await BackgroundGeolocation.stop();

openSettings

장치의 위치 설정 페이지를 엽니다. 사용자에게 위치 서비스를 활성화하거나 권한을 조정하도록 안내하는 데 유용합니다.

import { BackgroundGeolocation } from '@capgo/background-geolocation';

// Direct user to location settings
await BackgroundGeolocation.openSettings();

setPlannedRoute

사용자가 계획된 경로에서 벗어났을 때 사운드 파일을 재생합니다. 이 기능은 네이티브에서만 사용할 수 있으며, 배경에서도 재생할 수 있습니다.

import { BackgroundGeolocation } from '@capgo/background-geolocation';

await BackgroundGeolocation.setPlannedRoute({
  soundFile: "notification.mp3",
  route: [[-74.0060, 40.7128], [-118.2437, 34.0522]]
});

네이티브 지오펜싱

네이티브 iOS 및 Android 지오펜싱을 사용하여 매장, 작업장, 배송 구역, 캠퍼스, 또는 체크인 지역을 감시합니다. HTTP 또는 HTTPS url 네이티브 code POST 전환 패킷을 WebView가 중단된 상태에서 허용하도록 하려면:

import { BackgroundGeolocation } from '@capgo/background-geolocation';

await BackgroundGeolocation.setupGeofencing({
  url: 'https://api.example.com/geofences',
  notifyOnEntry: true,
  notifyOnExit: true,
  payload: { userId: '123' },
});

await BackgroundGeolocation.addGeofence({
  identifier: 'warehouse',
  latitude: 40.7128,
  longitude: -74.006,
  radius: 200,
});

const listener = await BackgroundGeolocation.addListener(
  'geofenceTransition',
  (event) => console.log(event.identifier, event.transition),
);

const errorListener = await BackgroundGeolocation.addListener(
  'geofenceError',
  (event) => console.error(event.identifier, event.message),
);

await BackgroundGeolocation.removeGeofence({ identifier: 'warehouse' });
await listener.remove();
await errorListener.remove();

Android에서만 사용할 때만 앱 매니페스트에 추가하십시오: ACCESS_BACKGROUND_LOCATION 자세한 설명

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

__CAPGO_KEEP_0__:

Using @capgo/background-geolocation

이 기능을 사용 중이라면 Using @capgo/background-geolocation 자연스러운 네이티브 플러그인 작업을 계획하려면 @capgo/background-geolocation 자연스러운 네이티브 플러그인 구현에 대한 구체적인 정보는 @capgo/background-geolocation Getting Started Getting Started의 구체적인 구현 정보 Capgo Plugin Directory Capgo Plugin Directory의 제품 워크플로우 Capacitor Plugins by Capgo Capacitor 플러그인의 구현 세부 사항은 Capgo에서 확인할 수 있습니다. 플러그인 추가 또는 업데이트 __CAPGO_KEEP_0__ 플러그인 추가 또는 업데이트 구현 세부 사항입니다.