Flutter - google map, does not show my location Flutter - google map, does not show my location flutter flutter

Flutter - google map, does not show my location


If you want to see your current location on the map, and enable the lower right FAB functionality that takes you there, make sure you have the property myLocationEnabled set to true on your GoogleMap Widget.

      [...]      body: GoogleMap(          myLocationEnabled: true,          [...]      )


you need to use the location package of flutter in order to track the location of the user, and you need to add this function to your code

_getLocation() async {    var location = new Location();    try {      currentLocation = await location.getLocation();      print("locationLatitude: ${currentLocation.latitude}");      print("locationLongitude: ${currentLocation.longitude}");      setState(          () {}); //rebuild the widget after getting the current location of the user    } on Exception {      currentLocation = null;    }  }

this function should be called in your initState() function as follows

@override  void initState() {    _getLocation();    super.initState();  }

and don't to forget to import the location package to your code,

import 'package:location/location.dart';

follow the installation guide of the location package as you need to add the location permission in AndroidManifest.xml for android and info.plist for iphonethe location package will be responsible for asking for location permission from the user at runtime

Hope it helps and good luck


You have to provide an access to your current locationios: Info.plist

    <key>NSLocationWhenInUseUsageDescription</key>    <string>Application needs to access your current location</string>    <key>NSLocationAlwaysUsageDescription</key>    <string>Application needs to access your current location</string>

android: AndroidManifest.xml

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