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.
The main code is divided into several components:
MapScreenwidget is a
StatefulWidgetthat displays the Google Map and the user’s city name.
- It utilizes the
GoogleMapViewModelto load the user’s current coordinates and
geocodingto 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.
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.
loadCurrentUserCoordinatesfunction returns a
LatLngobject with the user’s current latitude and longitude.
GoogleMapWidgetis a stateless widget that displays the Google Map using the
- It also handles the marker for the user’s current location, which can be tapped to show the coordinates in a dialog using the
- The main entry point of the app in
main.dartinitializes the app and sets up the MaterialApp.
- Clone this repository.
- Ensure you have Flutter and Dart installed.
flutter pub getto install the required dependencies.
- Run the app using
Here is a screenshot of the app in action:
- 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.
Feel free to contribute to this project by opening issues or creating pull requests.
This project is licensed under the MIT License – see the LICENSE file for details.