flutter_location_plus

pub version pub points license

Migrating from nativecode_location? This package is its direct replacement. See the Migration Guide below.

A Flutter plugin that fetches device location using native Android APIs — no Google Play Services, no extra SDKs, no bloat.

Works on any Android device including those without Google Play Services (e.g. Huawei, custom ROMs, emulators).


Features

  • One-shot location fetch from GPS, Network, or Passive provider
  • Smart "best" mode — picks the most accurate fix across all enabled providers automatically
  • Live streaming — continuous updates via a Dart Stream<LocationData>
  • Typed resultLocationData with lat, lng, provider, accuracy, speed, and time
  • Zero Google Play Services dependency
  • Automatic runtime permission request (Android 6+)
  • Configurable update interval and minimum distance threshold

Platform Support

Android iOS
✅ SDK 21+

Installation

dependencies:
  flutter_location_plus: ^1.0.0
flutter pub get

Android Setup

Add to your app's android/app/src/main/AndroidManifest.xml (inside <manifest>):

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

The plugin automatically requests runtime permissions on Android 6+. No extra setup needed.


Usage

One-shot location

import 'package:flutter_location_plus/flutter_location_plus.dart';

final location = FlutterLocationPlus();

// Best available fix (GPS → Network → Passive fallback)
final String? raw = await location.getBestLocation();
final LocationData? fix = raw != null ? LocationData.tryParse(raw) : null;

if (fix != null) {
  print('${fix.lat}, ${fix.lng} via ${fix.provider}');
  print('Accuracy: ±${fix.accuracy}m');
}

Fetch from a specific provider:

final gps     = await location.getGpsLocation();     // satellite
final network = await location.getNetworkLocation(); // cell / Wi-Fi
final passive = await location.getPassiveLocation(); // zero battery cost

Live location stream

late StreamSubscription<LocationData> _sub;

@override
void initState() {
  super.initState();
  _sub = location.liveLocation(
    provider: 'best',       // 'gps' | 'network' | 'passive' | 'best'
    intervalMs: 2000,       // minimum time between updates (ms)
    distanceMeters: 5,      // minimum distance between updates (m)
  ).listen((fix) {
    print('${fix.lat}, ${fix.lng}  ±${fix.accuracy}m  ${fix.speed * 3.6} km/h');
  }, onError: (e) => print('Location error: $e'));
}

@override
void dispose() {
  _sub.cancel();
  location.stopLiveLocation(); // removes the native listener
  super.dispose();
}

LocationData fields

Field Type Description
lat double Latitude (WGS-84)
lng double Longitude (WGS-84)
provider String "gps", "network", or "passive"
accuracy double Horizontal accuracy radius in metres
speed double Ground speed in m/s
time DateTime Timestamp of the fix

Error handling

getBestLocation() and provider-specific methods return a raw String?. Parse it safely:

final raw = await location.getBestLocation();
final fix = raw != null ? LocationData.tryParse(raw) : null;
// fix is null when: permission denied, provider disabled, or no cached fix yet

For live updates, attach an onError handler to the stream (see example above).


Provider comparison

Provider Accuracy Battery Works indoors
GPS ±3–10 m High
Network ±50–300 m Low
Passive Varies Zero
Best Best available Adaptive

Migration from nativecode_location

pubspec.yaml

# Remove
nativecode_location: ^0.0.1

# Add
flutter_location_plus: ^1.0.0

Dart code

Before (nativecode_location) After (flutter_location_plus)
import 'package:nativecode_location/nativecode_location.dart' import 'package:flutter_location_plus/flutter_location_plus.dart'
NativecodeLocation() FlutterLocationPlus()
plugin.getNativeCodeLocation() location.getBestLocation()
Manual split(',') parsing LocationData.tryParse(raw)
No live streaming location.liveLocation(...)

Requirements

  • Flutter ≥ 3.19
  • Dart ≥ 3.3
  • Android SDK ≥ 21 (Android 5.0 Lollipop)

Contributing

Issues and PRs are welcome at https://github.com/SR7911/flutter_location_plus.

License

MIT