location_pro 1.0.3
location_pro: ^1.0.3 copied to clipboard
A Flutter service for real-time location tracking with reverse geocoding (address lookup) using OpenStreetMap Nominatim API. Supports Android, iOS, Web, and Desktop.
# Location Pro π
A Flutter service for **real-time location tracking** with **address resolution**.
It supports **direct LatLng input**, allowing address fetch without live GPS, and provides **multi-language address support** for English, Bangla, Japanese, Chinese, and more.
---
## β¨ Features
* π‘ Real-time GPS tracking on **mobile**
* π Periodic location updates on **web/desktop**
* πΊοΈ Reverse geocoding with **OpenStreetMap Nominatim API**
* π Exposes **current LatLng** & **address** as `ValueNotifier`
* π Supports **direct LatLng input**: `startTracking(LatLng)`
* π Multi-language address support (English, Bangla, Japanese, Chinese, etc.)
* π± Cross-platform: Android, iOS, Web, Desktop
* π¦ Automatic **permission handling**
---
## π¦ Installation
Add to your `pubspec.yaml`:
```yaml
dependencies:
location_pro: ^Latest Version
Then fetch packages:
flutter pub get
Import in your Dart file:
import 'package:location_pro/location_pro.dart';
π οΈ Usage #
Initialize & Start Tracking #
final locationService = LocationPro();
// Start live GPS tracking
locationService.startTracking();
// Optional: Track a specific LatLng without live GPS
// locationService.startTracking(LatLng(23.8103, 90.4125));
// Listen to location updates
locationService.currentLocation.addListener(() {
print("π Current: ${locationService.currentLocation.value}");
});
// Listen to address updates
locationService.placeName.addListener(() {
print("π Address: ${locationService.placeName.value}");
});
Fetch Address in Specific Language #
// Example: Bangla
await locationService.getPlaceName(23.8103, 90.4125, langCode: 'bn');
// Example: Japanese
await locationService.getPlaceName(35.6895, 139.6917, langCode: 'ja');
// Example: Chinese
await locationService.getPlaceName(31.2304, 121.4737, langCode: 'zh-CN');
langCodefollows the IETF language tag format.
Stop Tracking #
locationService.stopTracking();
Manually Fetch Current Location #
await locationService.fetchCurrentLocation();
print("π Location: ${locationService.currentLocation.value}");
print("π Address: ${locationService.placeName.value}");
π API Reference #
| Method / Property | Type | Description |
|---|---|---|
startTracking([LatLng?]) |
void |
Start GPS tracking (mobile) or periodic updates (web/desktop). Optionally provide a LatLng. |
stopTracking() |
void |
Stop tracking & cancel subscriptions. |
fetchCurrentLocation() |
Future<void> |
Fetch current location & address once. |
getPlaceName(lat, lng, {langCode}) |
Future<void> |
Fetch address for given coordinates in specified language. |
currentLocation |
ValueNotifier<LatLng?> |
Exposes current latitude/longitude. |
placeName |
ValueNotifier<String> |
Exposes human-readable address. |
_isMobile() |
bool |
Returns true if running on Android/iOS. |
π Permissions Setup #
Android #
Add to 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.ACCESS_BACKGROUND_LOCATION"/>
iOS #
Add to ios/Runner/Info.plist:
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs your location to provide tracking features.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs your location to provide tracking features.</string>
π· Example Output #
β
Current location: LatLng(23.8103, 90.4125)
π Address (English): Dhaka, Bangladesh
π Address (Bangla): ΰ¦’ΰ¦Ύΰ¦ΰ¦Ύ, বাΰ¦ΰ¦²ΰ¦Ύΰ¦¦ΰ§ΰ¦Ά
π Address (Japanese): γγγ«γγγ³γ°γ©γγ·γ₯
π Address (Chinese): θΎΎε‘, εε ζε½
π§© Flutter Example Page #
import 'package:flutter/material.dart';
import 'package:location_pro/location_pro.dart';
class LocationPage extends StatefulWidget {
final LatLng? latLng;
const LocationPage({super.key, this.latLng});
@override
State<LocationPage> createState() => _LocationPageState();
}
class _LocationPageState extends State<LocationPage> {
final LocationPro locationService = LocationPro();
@override
void initState() {
super.initState();
locationService.startTracking(widget.latLng);
}
@override
void dispose() {
locationService.stopTracking();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Location Pro Example")),
body: Center(
child: ValueListenableBuilder<String>(
valueListenable: locationService.placeName,
builder: (context, address, _) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ValueListenableBuilder<LatLng?>(
valueListenable: locationService.currentLocation,
builder: (context, position, _) {
return Text(
position != null
? "Lat: ${position.latitude}, Lng: ${position.longitude}"
: "Fetching location...",
style: const TextStyle(fontSize: 16),
);
},
),
const SizedBox(height: 10),
Text(
address.isNotEmpty ? address : "Fetching address...",
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
),
],
);
},
),
),
);
}
}
π¨βπ» Developed By #
Md. Abdullah Al Siddik
β€οΈ Support #
If you like this package, give it a β on GitHub and share it!