title: Get user location using flutter
body: <p>I'm using the geolocator plugin to access the user's location but it seems like it does not work, cause when I run my code I get the error on message.</p>
  <p>I have done all the geolocation configuration, but I have the problem.</p>
  <p>Adding the Geolocator plugin(pubspec.yaml)</p>
  <pre><code>dependencies:
    flutter:
      sdk: flutter
    geolocator: ^5.1.3
  </code></pre>
  <p>For android, head on over to your AndroidManifest.xml and add either of these permissions:</p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; /&gt;
  </code></pre>
  <p>Source code for getting address</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:flutter/services.dart';
  import 'package:geolocator/geolocator.dart';
  
  class HomePage extends StatefulWidget {
    @override
    _HomePageState createState() =&gt; _HomePageState();
  }
  
  class _HomePageState extends State&lt;HomePage&gt; {
    final Geolocator geolocator = Geolocator()..forceAndroidLocationManager;
    Position _currentPosition;
    String _currentAddress;
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(&quot;Location&quot;),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: &lt;Widget&gt;[
              if (_currentPosition != null) Text(_currentAddress),
              FlatButton(
                child: Text(&quot;Get location&quot;),
                onPressed: () {
                  _getCurrentLocation();
                },
              ),
            ],
          ),
        ),
      );
    }
  
    _getCurrentLocation() {
      geolocator
          .getCurrentPosition(desiredAccuracy: LocationAccuracy.best)
          .then((Position position) {
        setState(() {
          _currentPosition = position;
        });
        _getAddressFromLatLng();
      }).catchError((e) {
        print(e);
      });
    }
  
    _getAddressFromLatLng() async {
      try {
        List&lt;Placemark&gt; p = await geolocator.placemarkFromCoordinates(
            _currentPosition.latitude, _currentPosition.longitude);
        Placemark place = p[0];
        setState(() {
          _currentAddress =
              &quot;${place.locality}, ${place.postalCode}, ${place.country}&quot;;
        });
      } catch (e) {
        print(e);
      }
    }
  }
  
  </code></pre>
  <p>The problem I get when I run my code is here.</p>
  <p><a href="https://i.stack.imgur.com/jJFcR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jJFcR.png" alt="My error massage" /></a></p>