location_pro 1.0.0 copy "location_pro: ^1.0.0" to clipboard
location_pro: ^1.0.0 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 reverse geocoding (address lookup) using OpenStreetMap Nominatim API.
Supports Android, iOS, Web, and Desktop.

It also supports direct LatLng input for fetching addresses without live GPS tracking, and you can fetch addresses in any language.


✨ Features #

  • πŸ“‘ Real-time GPS tracking on mobile
  • 🌍 Periodic location updates on web/desktop
  • πŸ—ΊοΈ Reverse geocoding with Nominatim API
  • πŸ”” Exposes current LatLng & address as ValueNotifier
  • πŸ“ Supports direct LatLng input: startTracking(LatLng)
  • 🌐 Supports multi-language address (English, Bangla, Japanese, Chinese, etc.)
  • πŸ“± Cross-platform support (Android, iOS, Web, Desktop)
  • 🚦 Automatic permission handling

πŸ“¦ Installation #

Add the package to your pubspec.yaml:

dependencies:
  location_pro: update the version number

Then run:

flutter pub get

Import the service:

import 'package:location_pro/location_pro.dart';

πŸ› οΈ Usage #

Initialize & Start Tracking #

final locationService = LocationService();

// Start tracking (live GPS)
locationService.startTracking();

// Optional: Track a specific LatLng without live GPS
// locationService.startTracking(LatLng(23.8103, 90.4125));

// Listen to live location updates
locationService.currentLocation.addListener(() {
  print("πŸ“ Current: ${locationService.currentLocation.value}");
});

// Listen to place name 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');

langCode follows 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 Starts live GPS tracking (mobile) or periodic updates (web/desktop). Can optionally provide a LatLng.
stopTracking() void Stops tracking & cancels subscriptions.
fetchCurrentLocation() Future<void> Fetches the current location & address once.
getPlaceName(lat, lng, {langCode}) Future<void> Fetches address for given coordinates in specified language.
currentLocation ValueNotifier<LatLng?> Exposes the current latitude/longitude.
placeName ValueNotifier<String> Exposes the resolved human-readable address.
isMobile() bool Returns true if running on Android/iOS.

πŸ”‘ Permissions Setup #

Android #

Add the following 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 this in 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 LocationService locationService = LocationService();

  @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


πŸ’‘ Contributing #

Contributions are welcome!

  1. Fork the repo
  2. Create your feature branch
  3. Commit your changes
  4. Open a Pull Request

❀️ Support #

If you like this package, give it a ⭐ on GitHub and share it!

1
likes
0
points
46
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter service for real-time location tracking with reverse geocoding (address lookup) using OpenStreetMap Nominatim API. Supports Android, iOS, Web, and Desktop.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, geolocator, http

More

Packages that depend on location_pro