geo_fence_utils

A production-ready Dart package for geofence calculations

Pub Version License Dart Tests Coverage


What is geo_fence_utils?

geo_fence_utils is a comprehensive Flutter/Dart package designed for handling geofence calculations and location-based operations.

It provides utilities for:

  • Calculating distances between geographic points
  • Detecting whether points lie within circular or polygonal boundaries
  • Performing batch operations on multiple locations efficiently

This package is ideal for developers building location-aware applications without dealing with complex geographic calculations.


πŸ“Έ Screenshots

Circle Geofence Polygon Geofence Custom Markers

🎯 Purpose

The primary purpose of this package is to simplify geospatial calculations in Flutter and Dart applications.

It handles complex geographic math so you can focus on building your application logic.


πŸš€ Common Use Cases

  • Delivery & Logistics – Determine if delivery addresses fall within service areas
  • Location-Based Notifications – Trigger alerts when users enter or exit zones
  • Asset Tracking – Monitor vehicles or equipment within boundaries
  • Gaming – Create location-based game zones
  • Security Systems – Detect devices leaving authorized areas
  • Attendance Systems – Check if users are inside allowed locations
  • Ride Sharing – Match drivers with passengers within radius
  • Marketing – Send location-based promotions

✨ Key Features

Feature Description
πŸ“ Accurate Distance Calculation Uses Haversine formula (~0.5% accuracy)
πŸ”΅ Circle Geofence Efficient point-in-circle detection
πŸ”Ί Polygon Geofence Ray casting algorithm for complex shapes
⚑ Batch Operations Process many points efficiently
πŸ—Ί Map Widgets Works with Flutter Map and Google Maps
πŸ“ Custom Markers Support PNG and SVG markers
🌍 Cross Platform Works on iOS, Android, Web, Desktop
πŸ§ͺ Well Tested 266 tests with 96% coverage
🧩 Pure Dart No native dependencies
πŸ”’ Type Safe Full null safety support

πŸ“¦ Installation

Add the package to your pubspec.yaml:

dependencies:
  geo_fence_utils: ^2.1.0

Then run:

flutter pub get

Or use Flutter CLI:

flutter pub add geo_fence_utils

πŸ“š Documentation

Full usage examples are available in the example app.

➑ See example usage here:

example/README.md

The example demonstrates:

  • Creating geofence circles
  • Creating polygon boundaries
  • Drawing polylines
  • Adding custom markers
  • Displaying geofences on maps
  • Running geofence detection logic

🧩 Package Overview

Core Models

The package provides three main data models:

  • GeoPoint – Represents a geographic coordinate
  • GeoCircle – Circular geofence with center and radius
  • GeoPolygon – Polygon geofence with multiple vertices

Services

Three main service classes handle operations:

  • GeoDistanceService

    • Calculate distance between points
    • Find closest or farthest point
  • GeoCircleService

    • Check points inside circles
    • Detect circle overlap
  • GeoPolygonService

    • Point inside polygon
    • Polygon area and perimeter

Map Widgets

Interactive widgets for visualizing geofences:

  • GeoGeofenceMap – Main map widget
  • GeoCircleWidget – Circular geofence display
  • GeoPolygonWidget – Polygon geofence display
  • GeoPolylineWidget – Route and path display
  • GeoMarkerWidget – Custom markers (PNG/SVG)

βš™ Technical Details

  • Coordinate System: WGS 84 (GPS standard)

  • Distance Formula: Haversine

  • Distance Units: Meters

  • Supported Platforms:

    • iOS
    • Android
    • Web
    • Windows
    • macOS
    • Linux

⚑ Performance

Operation Time Complexity Notes
Distance calculation O(1) Constant time
Circle containment O(1) Constant time
Polygon containment O(n) Linear with vertices
Batch filtering O(nΓ—m) n points, m vertices

πŸ“š Documentation & Resources


πŸ§ͺ Testing

Run tests:

flutter test

Generate coverage report:

flutter test --coverage
genhtml coverage/lcov.info -o coverage/html

🀝 Contributing

Contributions are welcome.

Please ensure:

  • All tests pass
  • Code follows Dart style guidelines
  • New features include tests
  • Documentation updated

Steps:

  1. Fork repository
  2. Create feature branch
  3. Commit changes
  4. Push branch
  5. Open Pull Request

πŸ“„ License

This project is licensed under the MIT License.

See the LICENSE file for details.


Built with ❀️ for the Flutter/Dart community