Flutter geolocator package not retrieving location

9,550

Solution 1

I was facing the same issue. But my app started running after adding this.

[ Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true; ]

Hope it will work.

    Future<void> getCurrentLocation() async {
    try {
      Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;

      Position position = await Geolocator().getCurrentPosition(
        desiredAccuracy: LocationAccuracy.best,
      );

      return position;
    } catch (err) {
      print(err.message);
    }
  }

All the best.

Solution 2

On iOS you'll need to add the following entries to your Info.plist file (located under ios/Runner) in order to access the device's location. Simply open your Info.plist file and add the following:

<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location when in the background.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs access to location when open and in the background.</string>

Solution 3

I was facing the same issue now it works, I've just added forceAndroidLocationManager: true to the Geolocator.getCurrentPosition.

Position position = await 
    Geolocator.getCurrentPosition(forceAndroidLocationManager: true,
    desiredAccuracy: LocationAccuracy.lowest);

Solution 4

I was struggling with this problem for about 2 days. After that, I figured out this (Mac):

  1. In Simulator iOS did not work anyway;
  2. Connect an iOS real device After open iOS module in XCode as follow
  3. Right-click on folder project
  4. Choose Flutter->Open iOS module in XCode
  5. On XCode, Select TAGETS -> Runner
  6. In Signing & Capabilities:
  7. Set the Team
  8. Change the Bundle Identifier to a unique one (ex.:co.test.app456)
  9. Run your app in XCode (it will work)
  10. Close XCode and go back to your project in Flutter
  11. Select the real iOS device and run your app

Solution 5

I had the same issue i.e it was not returning anything but keep fecthing location so i just changed from this

forceAndroidLocationManager: true

to this

forceAndroidLocationManager: false
Geolocator.getCurrentPosition(
            desiredAccuracy: LocationAccuracy.bestForNavigation,
            forceAndroidLocationManager: false)
        .then((position) {
      print(position);
    });

Now its working fine. The problem is in new update because in the old package it was working fine

Share:
9,550
wagnerdelima
Author by

wagnerdelima

Updated on December 05, 2022

Comments

  • wagnerdelima
    wagnerdelima over 1 year

    I've open an issue on the geolocator repository https://github.com/BaseflowIT/flutter-geolocator/issues/199

    It entails the geolocator package not retrieving the location. They recently released a new version 3.0.0 and after that the I have had only aftermath.

    I am using the correct dependencies:

    dependencies:
     geolocator: '^3.0.0'
    
    targetSdkVersion 28 and compileSdkVersion 28
    

    Flutter doctor gives me this:

    [✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.3 18D109, locale en-US)
    [✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    [✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    [✓] Android Studio (version 3.2)
    [✓] IntelliJ IDEA Community Edition (version 2018.2.5)
    [✓] Connected device (1 available)
    
    • No issues found!
    

    Once I call await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high); the code just doesn't return anything and I have this output in terminal:

    I/DynamiteModule( 4233): Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:221 I/DynamiteModule( 4233): Selected remote version of com.google.android.gms.maps_dynamite, version >= 221 V/DynamiteModule( 4233): Dynamite loader version >= 2, using loadModule2NoCrashUtils W/System ( 4233): ClassLoader referenced unknown path: W/System ( 4233): ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000030/n/armeabi-v7a W/System ( 4233): ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000030/n/armeabi I/Google Maps Android API( 4233): Google Play services client version: 12451000 I/Google Maps Android API( 4233): Google Play services package version: 15090018 W/DynamiteModule( 4233): Local module descriptor class for com.google.android.gms.googlecertificates not found. I/DynamiteModule( 4233): Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4 I/DynamiteModule( 4233): Selected remote version of com.google.android.gms.googlecertificates, version >= 4 W/System ( 4233): ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/0000002f/n/armeabi-v7a W/System ( 4233): ClassLoader referenced unknown path: /data/user_de/0/com.goo`gle.android.gms/app_chimera/m/0000002f/n/armeabi

    I have spent a considerable amount of time on this. I am new to flutter and know that I may be missing a small thing to make it work.