How to implement geofencing in Flutter

2.3k Views Asked by At

I'm working on a Flutter application and I'm trying to implement geofencing functionality. I want to be able to track when a user enters or exits predefined geographic regions and perform certain actions based on their location. However, I'm not sure where to start or what packages or APIs to use.

Could someone provide a step-by-step guide or example code on how to implement geofencing in Flutter? It would be really helpful if you could explain the concepts involved and recommend the most reliable and up-to-date packages or APIs to use for geofencing.

Thank you in advance!

I've looked into the Flutter geofencing packages available, such as easy_geofencing, geofence_flutter but it has limitation defined in their description, (note that the easy_geofencing/geofence_flutter plugin doesn't support receiving an processing geofence status updates while running in the background), geofencing(this is not dart3 compatible)**,

I also looked this link https://medium.com/flutter/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124#6db8, but I'm having trouble understanding how to use them effectively for my use case.

Here are the specific requirements for my geofencing implementation:

  • Detect when the user enters or exits these predefined geofence regions.
  • Geofencing runs in background, even, start its service when mobile restart or boot.
  • Perform specific actions or show notifications when the user's location matches the geofence criteria.
1

There are 1 best solutions below

0
Marco Lettieri On

Geofence is a feature present in Android e iOS and allows to be notified if the device enter/exit or stay in an area of interest. In Flutter the best way to proceed is to make a plugin with native code for Android e iOS. I've forked a working library and improved it due better compatibility with android 12 and later, you can find it here: https://github.com/marcolettieri/FlutterGeofencing

The original author of the library have wrote a clear guide that you can find in readme.

here the documentation for Android: https://developer.android.com/training/location/geofencing

and for iOS: https://developer.apple.com/documentation/corelocation/monitoring_the_user_s_proximity_to_geographic_regions