搜索插件、代码仓与 APP 分类

easy_geofencing 封面
插件详情v0.2.0

easy_geofencing

这是一个 Dart 包,为 Android 和 iOS 提供最佳且经过优化的地理围栏后台服务功能。

AndroidiOSWebmacOS
近 30 天下载
81
喜欢数
61
Pub 分数
125

安装插件

flutter pub add easy_geofencing

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

EasyGeofencing 是一个 Dart 包,为 Android 和 iOS 提供优化的后台地理围栏服务,并支持 Web 和 macOS。它使开发者能够监控地理边界,并在用户进入或退出定义区域时触发事件,即使应用程序处于后台运行状态。该包简化了与原生平台功能的集成,确保高效的电池使用和可靠的定位跟踪。专为实时位置相关应用设计,它提供了跨多个平台管理地理围栏的简化 API。

适合场景

  • 实时位置跟踪
  • 基于位置的通知
  • 资产追踪
  • 配送与物流监控
  • 用户签到系统

主要特点

  • 跨平台支持(Android、iOS、Web、macOS)
  • 高效的后台地理围栏
  • 低电池消耗
  • 用于地理围栏管理的简单 API
  • 实时进出事件检测

适合对象

  • 需要位置感知的移动应用
  • 物流和配送服务
  • 健身和户外活动应用
  • 零售和营销活动
  • 智能家居和物联网集成

使用建议

  • 所有平台都需要位置权限
  • 后台执行可能因操作系统策略而异
  • 电池优化设置可能会影响性能
  • 某些设备的地理围栏半径限制
  • 需要对权限请求和用户同意进行适当处理

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

EASY GEOFENCING

Easy Geofencing

Easy Geofencing is a flutter geofencing package for flutter application (android & ios) which provides geofencing functionalities.It is completely written in pure dart language.

FEATURES

features

  • Geofence status triggered on location changes[init,enter,exit] as a geofence Status
  • Get continuous geofence status updates
  • Optimized dart code
  • battery optimized dart package

USAGE

usage

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

FOR ANDROID

AndroidX

The easy_geofencing 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 30:
android {
  compileSdkVersion 30

  ...
}
  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 easy_geofencing plugin doesn't support receiving an processing geofence status 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 EASY GEOFENCING SERVICES

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

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

EasyGeofencing.startGeofenceService(
    pointedLatitude: "34.2165157",
    pointedLongitude: "71.9437819",
    radiusMeter: "250.0",
    eventPeriodInSeconds: 5
);
GET GEOFENCE STATUS STREAMS

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

import 'package:easy_geofencing/easy_geofencing.dart';

StreamSubscription<GeofenceStatus> geofenceStatusStream = EasyGeofencing.getGeofenceStream().listen(
  (GeofenceStatus status) {
    print(status.toString());
});
Stop Geofence Service

To stop geofence service you need to specify this:

import 'package:easy_geofencing/easy_geofencing.dart';

EasyGeofencing.stopGeofenceService();

Also, stop GeofenceStatus stream subscription listener which is geofenceStatusStream in our case

geofenceStatusStream.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 easy_geofencing plugin for Flutter is developed by uzairleo.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。