Flutter Location Services
A simple, all-in-one package for live location tracking, geofencing, routing, and background data synchronization.
Features
- 📍 Live Tracking: Get user location in foreground & background.
- 🔋 Battery Efficient: Uses persistent foreground services for reliable background tracking.
- 🚧 Geofencing: Easy-to-use "Enter" and "Exit" region events.
- 🛣️ Routing: Draw routes on Google Maps with one line of code.
- ☁️ Firebase Sync: Automatically sync location data to your cloud database.
Quick Start
1. Installation
Add to your pubspec.yaml:
dependencies:
flutter_location_services: ^0.0.1
2. Basic Usage
Initialize the package in your main() method:
import 'package:flutter_location_services/flutter_location_services.dart';
void main() {
SmartLocation.configure(
apiKey: 'YOUR_GOOGLE_MAPS_API_KEY', // Required for Maps & Routing
debugMode: true, // See logs in console
);
runApp(MyApp());
}
3. Start Tracking
To start tracking location (even when app is closed):
await SmartLocation.startBackgroundTracking();
To stop:
await SmartLocation.stopBackgroundTracking();
4. Routing
Get a route between two points:
final route = await SmartLocation.getRoute(
source: LatLng(37.4, -122.0),
destination: LatLng(37.5, -122.1),
);
// Display the route on your map
// (See example app for full UI implementation)
5. Geofencing
Trigger actions when a user enters a specific area:
SmartLocation.addGeofence(
GeofenceRegion(
id: 'home',
latitude: 37.422,
longitude: -122.084,
radiusMeters: 200,
onEnter: (_) => print('Welcome Home!'),
onExit: (_) => print('Goodbye!'),
),
);
Setup Guide
Android
- Add permissions to
android/app/src/main/AndroidManifest.xml:ACCESS_FINE_LOCATIONACCESS_BACKGROUND_LOCATIONFOREGROUND_SERVICE
- Add your Google Maps API Key in
AndroidManifest.xml.
iOS
- Add
NSLocationAlwaysAndWhenInUseUsageDescriptiontoInfo.plist. - Enable "Background Modes" -> "Location updates" in Xcode.
Created with ❤️ for the Flutter community.