Skip to content

A simple Flutter app that fetches the user's real-time location, including latitude, longitude, city, and country, using the Geolocator package. Works on Android & iOS! πŸš€

License

Notifications You must be signed in to change notification settings

AmirBayat0/Location-Tracking-Flutter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌍 Flutter User Location App

πŸš€ Get the user's real-time location (latitude, longitude, city, and country) using Flutter and the Geolocator package!

Main

✨ Features

  • βœ… Fetch real-time latitude & longitude of the user.
  • βœ… Convert coordinates to city, country, and full address.
  • βœ… Auto-refresh location on startup & via button press.
  • βœ… Cupertino-style loading indicator for a smooth UI experience.
  • βœ… Works on Android, iOS, and Web.

πŸš€ Getting Started

1️⃣ Clone the repository

git clone https://github.com/your-username/flutter-user-location.git
cd flutter-user-location

2️⃣ Install dependencies

flutter pub get

3️⃣ Run the app

flutter run

πŸ› οΈ Setup & Permissions

πŸ“Œ Android Add the following permissions to your AndroidManifest.xml:

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

πŸ“Œ iOS Update your Info.plist:

<key>NSLocationWhenInUseUsageDescription</key>
<string>We need your location to show relevant data</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>We need your location even when the app is in the background</string>

πŸ—οΈ Project Structure

πŸ“‚ lib/
┣ πŸ“œ main.dart           // Entry point of the app
┣ πŸ“œ final_view.dart     // Main screen UI & logic
┣ πŸ“œ location_helper.dart // Handles location fetching & processing

πŸ“œ Code Overview

πŸ”Ή Fetch User Location

Position position = await Geolocator.getCurrentPosition(
   desiredAccuracy: LocationAccuracy.high,
);

πŸ”Ή Convert Coordinates to City & Country

List<Placemark> placemarks = await placemarkFromCoordinates(
   position.latitude, position.longitude,
);

πŸ”Ή Display Location in UI

setState(() {
 userLocation = 'City: ${place.locality}, Country: ${place.country}';
});

πŸ“Œ Contribution

Want to contribute? Feel free to fork this repo and submit a PR! πŸš€

πŸ† Show Some Love

⭐ Star this repo if you like it!🐦 Follow me on Twitter for more cool projects!

πŸ“œ License

This project is licensed under the MIT License.