Guide
iOS 및 Android에서 __CAPGO_KEEP_0__ 앱에 대한 정확한 배경 지리 정보 및 네이티브 지리 경계 설정
@capgo/background-geolocation을 사용하여
iOS 및 Android에서 Capacitor 앱에 대한 정확한 배경 지리 정보 및 네이티브 지리 경계 설정을 제공합니다. 사용자 위치 업데이트를 스트리밍하고 원형 영역을 모니터링하고 JavaScript 또는 백엔드에 지리 경계 진입/이탈 전환을 전달하여 계획된 경로에서 사용자가 떠나는 경우 네이티브 소리를 재생합니다.
설치
bun add @capgo/background-geolocation
bunx cap sync
이 플러그인이 제공하는 것
start- 전면 또는 배경 위치 업데이트를 스트리밍합니다.stop- 활성 위치 추적을 중지합니다.openSettings- 사용자가 위치 권한을 수정해야 할 때 native 설정을 열어줍니다.setPlannedRoute- 사용자가 계획된 경로에서 떠날 때 네이티브 소리를 재생합니다.setupGeofencing- 네이티브 지리 경계 기본값을 구성하고 옵션 전환 웹후크 전달을 제공합니다.addGeofence- iOS 또는 Android의 원형 지오펜스 지역을 모니터링합니다.removeGeofence/removeAllGeofences- 등록된 지역 중 하나 또는 모든 지역을 모니터링 중지합니다.getMonitoredGeofences- 모니터링 중인 지역 식별자 목록을 표시합니다.geofenceTransitionlistener - 앱이 활성화된 동안 입장 및 출입 이벤트를 받습니다.geofenceErrorlistener - 전환 이벤트와 함께 native 모니터링 오류를 별도로 처리합니다.
예시 사용
start
장치의 위치를 변경하는 변경 사항을 듣기 시작하려면 이 메서드를 호출하세요. Promise는 호출이 완료되었음을 나타내며, callback은 새로운 위치가 사용 가능한 경우 또는 이 메서드를 호출할 때 오류가 발생한 경우 호출됩니다. 이 메서드의 오류 처리에 대한 Promise 거부에 의존하지 마세요.
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
사용자가 계획된 경로에서 벗어났을 때 사운드 파일을 재생합니다. 이 메서드는 native에서만 백그라운드에서도 사운드 재생을 위해 사용해야 합니다.
import { BackgroundGeolocation } from '@capgo/background-geolocation';
await BackgroundGeolocation.setPlannedRoute({
soundFile: "notification.mp3",
route: [[-74.0060, 40.7128], [-118.2437, 34.0522]]
});
Native geofencing
native iOS 및 Android 지오펜스를 사용하여 매장, 작업장, 배송 구역, 캠퍼스, 또는 체크인 지역을 모니터링합니다. HTTP 또는 HTTPS URL을 추가하세요. url native 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" />
전체 참조
- GitHub: https://github.com/Cap-go/capacitor-백그라운드-지오페싱/
- 문서: /docs/plugins/background-geolocation/
native capgo POST 전환 패이로드를 WebView가 중단된 동안 계속하세요.
native __CAPGO_KEEP_0__ POST 전환 패이로드를 WebView가 중단된 동안 사용하는 경우 native capgo POST 전환 패이로드를 WebView가 중단된 동안 사용하는 경우 native __CAPGO_KEEP_0__ POST 전환 패이로드를 WebView가 중단된 동안 사용하는 경우 @capgo/background-geolocation for the implementation detail in @capgo/background-geolocation, Getting Started Getting Started 구현 세부 정보에 대해 Capgo 플러그인 디렉토리 Capgo 플러그인 디렉토리에서 제품 워크플로우에 대해 Capacitor 플러그인들에 의해 Capgo Capacitor 플러그인들에 의해 Capgo에 대해 구현 세부 정보 플러그인 추가 또는 업데이트 플러그인 추가 또는 업데이트 구현 세부 정보