搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.0

geofence_flutter

適用於 Flutter 應用程式(Android 和 iOS)的地點圍欄外掛程式。

AndroidiOSWebmacOSWindows
近 30 天下載
25
喜歡數
24
Pub 分數
140

安裝套件

flutter pub add geofence_flutter

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Geofence Flutter 是一個跨平台插件,可在 Flutter 應用程式中為 Android、iOS、Web、macOS 和 Windows 提供地理圍欄功能。它允許開發者監控裝置何時進入或離開預定的地理區域,非常適合用於基於位置的觸發器。該插件與各平台的原生地理圍欄 API 無縫整合,即使應用程式在背景運行也能可靠地偵測事件。支援圓形和自訂形狀的地理圍欄,並可設定監控間隔與精確度。設計簡潔且效能出色,適用於需要即時位置感知的應用。

適用情境

  • 基於位置的通知
  • 接近警示
  • 資產追蹤
  • 上下文感知應用
  • 自動簽到

主要特色

  • 跨平台支援(Android、iOS、Web、macOS、Windows)
  • 背景地理圍欄監控
  • 自定地理圍欄形狀
  • 事件驅動的 API 用於進入/退出
  • 可設定的精確度與更新間隔

適合對象

  • 具備位置智慧的行動應用程式
  • 現場服務管理工具
  • 智慧零售體驗
  • 物流與配送追蹤
  • 戶外活動應用

使用建議

  • 所有平台都需要位置權限
  • 頻繁監控可能導致電池使用量增加
  • 準確性取決於設備硬體和網路狀況
  • Web 支援僅限於瀏覽器地理定位 API
  • iOS 和 Android 上的後台執行限制

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Flutter Geofence

A flutter geofencing plugin for flutter application (android & ios) which provides geofencing functionalities.

Features

  • Geofence event triggered on location changes
  • Get continuous geofence event updates

Usage

To add the geofence_flutter to your flutter application read the install instructions. Below are some Android and iOS specifics that are required for the geofence_flutter to work correctly.

For android

AndroidX

The geofence_flutter plugin requires the AndroidX version of the Android Support Libraries. This means you need to make sure your Android project supports AndroidX. Detailed instructions can be found here.

The TL;DR version is:

  1. Add the following to your "gradle.properties" file:
android.useAndroidX=true
android.enableJetifier=true
  1. Make sure you set the compileSdkVersion in your "android/app/build.gradle" file to 33:
android {
  compileSdkVersion 33

  ...
}
  1. Make sure you replace all the android. dependencies to their AndroidX counterparts (a full list can be found here: https://developer.android.com/jetpack/androidx/migrate).

Permissions

On Android you'll need to add either the ACCESS_COARSE_LOCATION or the ACCESS_FINE_LOCATION permission to your Android Manifest. To do so open the AndroidManifest.xml file (located under android/app/src/main) and add one of the following two lines as direct children of the <manifest> tag (when you configure both permissions the ACCESS_FINE_LOCATION will be used):

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

Starting from Android 10 you need to add the ACCESS_BACKGROUND_LOCATION permission (next to the ACCESS_COARSE_LOCATION or the ACCESS_FINE_LOCATION permission) if you want to continue receiving updates even when your App is running in the background (note that the geofence_flutter plugin doesn't support receiving an processing geofence event updates while running in the background):

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

For ios

On iOS you'll need to add the following entries to your Info.plist file (located under ios/Runner) in order to access the device's location. Simply open your Info.plist file and add the following:

<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location when in the background.</string>

If you would like to receive updates when your App is in the background, you'll also need to add the Background Modes capability to your XCode project (Project > Signing and Capabilities > "+ Capability" button) and select Location Updates. Be careful with this, you will need to explain in detail to Apple why your App needs this when submitting your App to the AppStore. If Apple isn't satisfied with the explanation your App will be rejected.

API

Start Geofence Service

At first you need to start the geofence service and for that you need to pass the following parameters:

  • pointedLatitude: the latitude of the geofence area center
  • pointedLongitude: the longitude of the geofence area center
  • radiusMeter: the radius of the geofence area in meters
  • eventPeriodInSeconds: geofence event stream period in seconds
import 'package:geofence_flutter/geofence_flutter.dart';

await Geofence.startGeofenceService(
    pointedLatitude: "52.2165157",
    pointedLongitude: "6.9437819",
    radiusMeter: "50.0",
    eventPeriodInSeconds: 10
);
Get Geofence Event Streams

To get the stream geofence event updates on location changes, you need to subscribe getGeofenceStream to listen geofence event streams on current location updates.

import 'package:geofence_flutter/geofence_flutter.dart';

StreamSubscription<GeofenceEvent> geofenceEventStream = Geofence.getGeofenceStream()?.listen(
  (GeofenceEvent event) {
    print(event.toString());
});
Stop Geofence Service

To stop geofence service you need to specify this:

import 'package:geofence_flutter/geofence_flutter.dart';

Geofence.stopGeofenceService();

Also, stop GeofenceEvent stream subscription listener which is geofenceEventStream in our case

geofenceEventStream?.cancel();

Issues

Please file any issues, bugs or feature requests as an issue on our GitHub page.

Dependencies

This plugin is depended on geolocator plugin of baseflow.com

Want to contribute

If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), feel free to send your pull request.

Author

This geofence_flutter plugin for Flutter is developed by Sarfaraz.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。