A Flutter plugin for native GPS location tracking with configurable interval and accuracy filter. Currently supports iOS only.
- 📍 Location tracking with a configurable time interval
- 🎯 Accuracy filter — discard low-quality GPS fixes
- 🔋 Background location updates via
CLLocationManager
- ⏸ Pause / resume / stop controls
- 📡 Real-time location stream via
EventChannel
- 🛑 Native errors forwarded to Flutter as
PlatformException
dependencies:
flutter_native_location:
git:
url: https://github.com/yanuarif/flutter_native_location
Add the following keys to ios/Runner/Info.plist:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Required to track your location while the app is open.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Required to track your location in the background.</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
1. Initialise once (e.g. in main.dart) #
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await FlutterNativeLocation.init(
LocationConfig(
intervalSeconds: 5, // emit a location every 5 seconds
accuracy: LocationAccuracy.high, // filter fixes worse than ~25 m
autoStart: true, // start tracking right after permission is granted
),
);
runApp(const MyApp());
}
final tracker = FlutterNativeLocation.instance;
tracker.locationStream.listen(
(Position point) {
print('${point.latitude}, ${point.longitude}');
print('Speed: ${point.speedKmh} km/h');
print('Accuracy: ±${point.accuracy} m');
},
onError: (error) {
// PlatformException forwarded from native (e.g. permission denied)
print('Location error: $error');
},
);
await tracker.startTracking(); // start (or restart)
await tracker.pauseTracking(); // pause emission, keep CLLocationManager alive
await tracker.resumeTracking(); // resume after pause
await tracker.stopTracking(); // stop and release resources
// Check current state
print(tracker.state); // TrackingState.idle | tracking | paused | error
// Fetch authoritative state from native
final state = await tracker.getTrackingState();
// Get last known position
final last = await tracker.getLastLocation();
// Reconfigure on the fly (restarts tracking if active)
await tracker.reconfigure(
LocationConfig(intervalSeconds: 10, accuracy: LocationAccuracy.medium),
);
| Parameter |
Type |
Default |
Description |
intervalSeconds |
int |
5 |
How often a location snapshot is emitted (seconds) |
accuracy |
LocationAccuracy |
high |
GPS fix quality filter |
autoStart |
bool |
false |
Start tracking automatically after init() |
| Value |
Max horizontal accuracy |
iOS desiredAccuracy |
best |
~5 m |
kCLLocationAccuracyBest |
high |
~25 m |
kCLLocationAccuracyNearestTenMeters |
medium |
~100 m |
kCLLocationAccuracyHundredMeters |
low |
~1000 m |
kCLLocationAccuracyKilometer |
lowest |
~3000 m |
kCLLocationAccuracyThreeKilometers |
| Field |
Type |
Description |
latitude |
double? |
Degrees |
longitude |
double? |
Degrees |
timestamp |
DateTime? |
Time of the fix |
accuracy |
double? |
Horizontal accuracy in metres |
altitude |
double? |
Metres above sea level |
altitudeAccuracy |
double? |
Vertical accuracy in metres |
heading |
double? |
Direction of travel (degrees, 0–360), -1 if invalid |
headingAccuracy |
double? |
Heading accuracy in degrees |
speed |
double? |
Speed in m/s, -1 if invalid |
speedAccuracy |
double? |
Speed accuracy in m/s |
speedKmh |
double? |
Speed in km/h (computed from speed), null if invalid |
| Platform |
Support |
| iOS |
✅ |
| Android |
🔜 Planned |