A lightweight and easy-to-use Flutter plugin for:
- Reverse geocoding
- Forward geocoding
- Address formatting
- Distance calculations
- Coordinate extensions
- Batch geocoding
- Address caching
Built on top of the Flutter geocoding platform APIs.
✅ Reverse geocoding
✅ Forward geocoding
✅ Address model support
✅ Coordinate extensions
✅ Distance calculation
✅ Batch APIs
✅ In-memory caching
✅ Retry support
✅ Timeout handling
✅ Backward compatibility APIs
Add this to your pubspec.yaml:
dependencies:
location_provider: 1.0.0Then run:
flutter pub get| Platform | Support |
|---|---|
| Android | ✅ |
| iOS | ✅ |
To use this plugin, please follow the installation guide on the official geocoding plugin page.
NOTE: This plugin relies on the AndroidX version of the Android Support Libraries. This means you need to make sure your Android project is also upgraded to support AndroidX. Detailed instructions can be found here.
The TL;DR version is:
- Add the following to your "gradle.properties" file:
android.useAndroidX=true android.enableJetifier=true
- Make sure you set the
compileSdkVersionin your "android/app/build.gradle" file to 31:android { compileSdkVersion 31 ... }
- Make sure you replace all the
android.dependencies to their AndroidX counterparts (a full list can be found Android migration guide).
import 'package:location_provider/location_provider.dart';Convert coordinates into an address.
final address = await LocationHelper.getAddress(
28.6139,
77.2090,
);
print(address?.fullAddress);final city = await LocationHelper.getCity(
28.6139,
77.2090,
);
final state = await LocationHelper.getState(
28.6139,
77.2090,
);
final country = await LocationHelper.getCountry(
28.6139,
77.2090,
);Convert address into coordinates.
final location =
await LocationHelper.getLocationFromAddress(
'New Delhi',
);
print(location?.lat);
print(location?.lng);final address = await LocationHelper.getAddress(
28.6139,
77.2090,
);
print(address?.city);
print(address?.state);
print(address?.country);
print(address?.postalCode);print(address?.shortAddress);
print(address?.fullAddress);final coords = (
lat: 28.6139,
lng: 77.2090,
);
final city = await coords.city;
final address = await coords.address;final delhi = (
lat: 28.6139,
lng: 77.2090,
);
final mumbai = (
lat: 19.0760,
lng: 72.8777,
);
final distance =
delhi.distanceBetween(mumbai);
print(distance);The package provides multiple Dart extensions for a cleaner and more readable API.
Work directly with coordinates.
final coords = (
lat: 28.6139,
lng: 77.2090,
);final city = await coords.city;
print(city);final state = await coords.state;
print(state);final country = await coords.country;
print(country);final address = await coords.address;
print(address?.fullAddress);final fullAddress =
await coords.fullAddress;
print(fullAddress);final shortAddress =
await coords.shortAddress;
print(shortAddress);final distance = coords.distanceTo(
19.0760,
72.8777,
);
print(distance);Convert an address string into coordinates.
final result =
await 'New Delhi'.coordinates;
print(result?.lat);
print(result?.lng);Format address objects easily.
final address = await coords.address;
print(address?.formatted);Calculate distance between two coordinates.
final delhi = (
lat: 28.6139,
lng: 77.2090,
);
final mumbai = (
lat: 19.0760,
lng: 72.8777,
);
final distance =
delhi.distanceBetween(mumbai);
print(distance);final locations =
await LocationHelper
.getLocationsFromAddresses([
'Delhi',
'Mumbai',
'Bangalore',
]);final addresses =
await LocationHelper.getAddressesBatch([
(28.6139, 77.2090),
(19.0760, 72.8777),
]);The package includes internal in-memory caching for optimized reverse geocoding.
LocationHelper.maxCacheSize = 200;Clear cache:
LocationHelper.clearCache();The following APIs are still supported for backward compatibility:
LocationHelper.getLatitudeFromAddress();
LocationHelper.getLongitudeFromAddress();
LocationHelper.getLocationFullAddress();
LocationHelper.getSubLocality();
LocationHelper.getLocality();Recommended migration:
LocationHelper.getLocationFromAddress();
LocationHelper.getAddress();
LocationHelper.getFormattedAddress();try {
final address =
await LocationHelper.getAddress(
28.6139,
77.2090,
);
} catch (e) {
print(e);
}This plugin uses the native geocoding services provided by Android and iOS.
Rate limits may apply depending on platform restrictions.
- Apple CoreLocation
- Android Geocoder APIs
See the /example folder for a complete Flutter example.
MIT License
This package extends the functionality of the
Flutter geocoding plugin by providing:
- Extension APIs
- Address formatting
- Distance calculations
- Batch utilities
- In-memory caching
- Cleaner helper methods
Core geocoding functionality is powered by the
geocoding package and native platform APIs.
