Flutter Google Map Geocoding and Geolocator

Flutter Google Map Geocoding and Geolocator

We will learn step by step how to use Google Map, Geolocator and Geocoding get user's locatoin and  we will see how to get user's location dynamically as user tap on the map and save the user selected location. we will connect to back end. 

We will cover the following topic

1. Show Google Map

2. Get address from lattiude and longittude

3. Get locatoin based on user interaction 

4. Save the location

Create a project

Let's go ahead and create a project for Google map. You can name it anything. Once the project has been created install these three packages

  google_maps_flutter: 
  geolocator: 
  geocoding: 

 

Flutter - Geolocator.getCurrentPosition never returns

 late Position _myPosition;
      Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best)
          .then((Position position) {
        _myPosition=position;

      print("Position "+_myPosition.toString());
      }).catchError((e) {
        _myPosition=Position(
          latitude: defaultLatLng != null ? defaultLatLng.latitude : double.parse( '0'),
          longitude: defaultLatLng != null ? defaultLatLng.longitude : double.parse( '0'),
          timestamp: DateTime.now(), accuracy: 1, altitude: 1, heading: 1, speed: 1, speedAccuracy: 1,
        );
        print("Error "+e);
      });

It works

Recent posts