geofencing_api 패키지는 Android, iOS 및 웹 플랫폼에서 원형 및 다각형 기반의 지오페싱을 구현할 수 있도록 개발자를 지원합니다. 지리적 경계를 모니터링하고 사용자가 정의된 영역에 들어가거나 나갈 때 이벤트를 트리거하는 통합 인터페이스를 제공합니다. 위치 기반 애플리케이션에 적합하며 최소한의 설정으로 실시간 위치 추적과 영역 모니터링을 지원합니다. 플러터 앱과 원활하게 통합되며, 최적의 성능과 배터리 효율을 위해 네이티브 지오페싱 기능을 활용합니다.
사용 사례
위치 기반 알림
자산 추적
근접 알림
지오페인스드 체크인
실시간 위치 모니터링
주요 기능
원형 및 다각형 지오펜싱
크로스 플랫폼 지원 (Android, iOS, Web)
네이티브 성능 통합
이벤트 기반 영역 모니터링
영역 관리를 위한 간단한 API
적합한 대상
위치 서비스를 갖춘 모바일 앱
현장 운영 추적
스마트 시티 애플리케이션
소매 근접 마케팅
물류 및 배송 시스템
고려 사항
위치 권한 필요
활성 모니터링 시 배터리 사용량이 증가할 수 있습니다
웹 지원은 최신 브라우저에 한정됩니다
다각형 정밀도는 장치의 정확성에 따라 달라집니다
일부 플랫폼에서의 백그라운드 실행 제약
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
This plugin is used to implement circular and polygon geofencing service.
[!CAUTION]
It does not use the geofencing api implemented in the platform.
Therefore, battery efficiency cannot be guaranteed.
Instead, this plugin can provide more accurate and real-time geofencing by navigating your location while your app is alive.
Features
Can create a circular type geofence.
Can create a polygon type geofence.
Can listen to geofence status changes in real-time.
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Used to collect location data in the background.</string><key>NSLocationAlwaysUsageDescription</key><string>Used to collect location data in the background.</string><key>UIBackgroundModes</key><array><string>fetch</string><string>location</string></array>
Request location permission. To start the geofencing service, the permission result must be always or whileInUse.
Future<bool> requestLocationPermission({bool background = false}) async {
if (!awaitGeofencing.instance.isLocationServicesEnabled) {
// Location services is disabled.returnfalse;
}
LocationPermission permission =
awaitGeofencing.instance.getLocationPermission();
if (permission == LocationPermission.denied) {
// Android: ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION// iOS 12-: NSLocationWhenInUseUsageDescription or NSLocationAlwaysAndWhenInUseUsageDescription// iOS 13+: NSLocationWhenInUseUsageDescription
permission = awaitGeofencing.instance.requestLocationPermission();
}
if (permission == LocationPermission.denied ||
permission == LocationPermission.deniedForever) {
// Location permission has been ${permission.name}.returnfalse;
}
// Web: Only allow whileInUse permission.if (kIsWeb || kIsWasm) {
returntrue;
}
// Android: You must request location permission one more time to access background location.// iOS 12-: You can request always permission through the above request.// iOS 13+: You can only request whileInUse permission through the above request.// When the app enters the background, a prompt will appear asking for always permission.if (Platform.isAndroid &&
background &&
permission == LocationPermission.whileInUse) {
// You need a clear explanation of why your app's feature needs access to background location.// https://developer.android.com/develop/sensors-and-location/location/permissions#request-background-location// Android: ACCESS_BACKGROUND_LOCATION
permission = awaitGeofencing.instance.requestLocationPermission();
if (permission != LocationPermission.always) {
// Location permission must always be granted to collect location in the background.returnfalse;
}
}
returntrue;
}
Set up the geofencing service.
interval: The millisecond interval at which to update the geofence status. This value may be delayed by device platform limitations. The default is 5000.
accuracy: The accuracy of the geofencing service in meters. The default is 100.
statusChangeDelay: The status change delay in milliseconds. GeofenceStatus.enter and GeofenceStatus.exit events may be called frequently when the location is near the boundary of the geofence. If the option value is too large, real-time geofencing is not possible, so use it carefully. The default is 10000.
allowsMockLocation: Whether to allow mock location. The default is false.
printsDebugLog: Whether to print debug logs in plugin. The default is true.