osm_location_picker 1.0.2
osm_location_picker: ^1.0.2 copied to clipboard
A self-contained Flutter location picker powered by OpenStreetMap. No API key required. Supports address search, GPS, and full theming.
osm_location_picker #
A self-contained Flutter location picker powered by OpenStreetMap.
No API key. No account. No billing. Everything runs on free, open-source map and geocoding services β making this package a great fit for small projects, prototypes, and indie apps that don't want the overhead of registering with Google Maps or Mapbox.
Users can pan/zoom the map, search for addresses, and tap to confirm a location. The package returns a LocationModel containing the selected address string and LatLng coordinates.
Features #
- πΊοΈ Interactive map using
flutter_map+ OpenStreetMap tiles - π Address search powered by the Nominatim geocoding service
- π Jump to the device's current GPS location with one tap
- π¨ Fully themeable via
LocationPickerTheme - π Built-in Arabic and English UI strings β extend with
LocationPickerStrings - ποΈ BLoC/Cubit state management β no global state pollution
- π¦ Zero external API keys needed
Platform support #
| Platform | Supported | Notes |
|---|---|---|
| Android | β | Full support |
| iOS | β | Full support |
| Web | β | Location uses browser Geolocation API β HTTPS required |
| macOS | β | Full support |
| Windows | β | Full support |
| Linux | β | Full support |
Note: GPS / current-location features depend on the
locationpackage. On platforms where device location is unavailable or denied, the map still opens and the user can search or tap a location manually β so the picker always works regardless of permission status.
Getting started #
1. Add the dependency #
dependencies:
osm_location_picker:
path: ../ # or the pub.dev version once published
2. Platform permissions #
Android β android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
iOS β ios/Runner/Info.plist
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to your location to show it on the map.</string>
Usage #
Push LocationPickerView as a full-screen route. It returns a LocationModel? when the user confirms a location.
import 'package:osm_location_picker/osm_location_picker.dart';
// Open the picker
final LocationModel? result = await Navigator.of(context).push<LocationModel>(
MaterialPageRoute(
builder: (_) => const LocationPickerView(),
),
);
if (result != null) {
print(result.address); // "Baghdad, Iraq"
print(result.latLng?.latitude); // 33.315241
print(result.latLng?.longitude); // 44.366085
}
Restore a previously selected location #
LocationPickerView(
initialLatLng: LatLng(33.315241, 44.366085),
initialAddress: 'Baghdad, Iraq',
)
Custom theme #
LocationPickerView(
theme: LocationPickerTheme(
primaryColor: Colors.teal,
backgroundColor: Colors.white,
),
)
Use LocationPickerTheme.of(context) to derive colours from your app's ThemeData automatically.
Custom strings / localisation #
LocationPickerView(
strings: LocationPickerStrings(
title: 'Pick a spot',
confirmLocation: 'Use this location',
searchHint: 'Search addressβ¦',
// β¦ all fields required
),
)
Built-in factories: LocationPickerStrings.en() and LocationPickerStrings.ar().
LocationPickerStrings.of(context) picks one automatically based on Localizations.localeOf(context).
LocationModel #
| Field | Type | Description |
|---|---|---|
address |
String? |
Human-readable address from Nominatim |
latLng |
LatLng? |
Coordinates (latlong2 package) |
// Serialise / deserialise
final json = model.toJson();
final model2 = LocationModel.fromJson(json);
Additional information #
- Map tiles Β© OpenStreetMap contributors
- Geocoding provided by Nominatim β please respect the usage policy
- File bugs and feature requests on the project's issue tracker
- Contributions are welcome β open a pull request with tests and a description of the change