Flutter GPS Task App
This Flutter app demonstrates how to use the Google Maps plugin to display a map with the user’s current location and fetch the city name based on the coordinates.
Code Overview
The main code is divided into several components:
MapScreen
- The
MapScreenwidget is aStatefulWidgetthat displays the Google Map and the user’s city name. - It utilizes the
GoogleMapViewModelto load the user’s current coordinates andgeocodingto fetch the city name. - The UI consists of a Google Map and a text field displaying the user’s city name.
- The user’s location is marked on the map, and tapping the marker opens a dialog displaying the coordinates.
GoogleMapViewModel
- The
GoogleMapViewModelis responsible for interacting with the Google Maps API and obtaining the user’s location. - It uses the
geolocatorpackage to check and request location permissions and to get the user’s current position. - The
loadCurrentUserCoordinatesfunction returns aLatLngobject with the user’s current latitude and longitude.
GoogleMapWidget and MarkerCoordinatesDialog
- The
GoogleMapWidgetis a stateless widget that displays the Google Map using thegoogle_maps_flutterpackage. - It also handles the marker for the user’s current location, which can be tapped to show the coordinates in a dialog using the
MarkerCoordinatesDialogwidget.
main.dart
- The main entry point of the app in
main.dartinitializes the app and sets up the MaterialApp.
Getting Started
- Clone this repository.
- Ensure you have Flutter and Dart installed.
- Run
flutter pub getto install the required dependencies. - Run the app using
flutter run.
Screenshots
Here is a screenshot of the app in action:

Note
- Make sure to add your Google Maps API key to your Flutter project if you plan to use this app on a real device or release it.
Contributing
Feel free to contribute to this project by opening issues or creating pull requests.
License
This project is licensed under the MIT License – see the LICENSE file for details.