Baseflow / flutter-geolocator

Android and iOS Geolocation plugin for Flutter
https://baseflow.com/
MIT License
1.24k stars 645 forks source link

location not retrieved by geolocator #731

Open sami7568 opened 3 years ago

sami7568 commented 3 years ago

geolocation.getCurrentLocation is not working in my flutter application.

i am using geolocator ^6.1.2 compileSdkVersion: 30 minSdkVersion: 21 targetSdkVersion: 30

afxgroup commented 3 years ago

Same here. But with latest version. It is stuck in await Geolocator.getCurrentPosition(); and never returns

zs-dima commented 3 years ago

if i use ACCESS_FILE_LOCATION i can get the location while if i use ACCESS_COARSE_LOCATION nothing is returned in the android emulator an it remain stuck in getCurrentPosition().

I have the same issue from 7.0.0 version to 7.0.3 geolocator version

https://github.com/Baseflow/flutter-geolocator/issues/507

florissmit1 commented 3 years ago

Can you provide more information about the device you're using? Be more specific about the issue, by providing your flutter doctor -v and maybe some example code. I must mention that there are known issues with Xiaomi devices.

zs-dima commented 3 years ago

@florissmit1 thanks for reply I have this issue on default Android emulator as well.

zs-dima commented 3 years ago

>flutter doctor -v
[√] Flutter (Channel dev, 2.3.0-12.1.pre, on Microsoft Windows [Version 10.0.19041.928], locale ru-RU)
    • Flutter version 2.3.0-12.1.pre at c:\...
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f9c825981c (3 days ago), 2021-05-18 14:07:52 -0700
    • Engine revision 26e217e6c3
    • Dart version 2.14.0 (build 2.14.0-edge.a527411e5100a0a4f48c4009087a1b988aa784af)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at c:\...
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = C:\...
    • Java binary at: c:\...
    • Java version Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\...

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.10.0 Preview 4.0)
    • Visual Studio at C:\...
    • Visual Studio Community 2019 version 16.10.31313.381
    • The current Visual Studio installation is a pre-release version. It may not be supported by Flutter yet.
    • Windows 10 SDK version 10.0.19041.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[√] IntelliJ IDEA Ultimate Edition (version 2019.3)
    • IntelliJ at C:\...
    • Flutter plugin version 43.0.3
    • Dart plugin version 193.6494.35

[√] IntelliJ IDEA Ultimate Edition (version 2021.1)
    • IntelliJ at C:\...
    • Flutter plugin version 56.0.5
    • Dart plugin version 211.7233

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19041.928]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 90.0.4430.212
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 90.0.818.62
Archit-crypto commented 3 years ago

using latest version of geolocator and flutter but can,t get the location after applying this code 'await Geolocator.getCurrentPosition(); '

Akash84016 commented 3 years ago

i am also faced same issue, its work few days ago when i complete testing and today i m check its not work

iamEtornam commented 3 years ago

I'm facing same issue on Samsung A21. Any possible fix?

Anullos commented 3 years ago

i have the same problem, " await Geolocator.getCurrentPosition(); " dont return Position, with mobile from honor8x

kirill-plotnikov commented 3 years ago

same issue

ghost commented 3 years ago

I have the same issue if my global location is active but "Use location in work profile" is off. It doesn't throw any error, just stucked.

Screenshot

[✓] Flutter (Channel stable, 2.2.1, on macOS 11.4 20F71 darwin-x64, locale fr-FR) • Flutter version 2.2.1 • Framework revision 02c026b03c (5 days ago), 2021-05-27 12:24:44 -0700 • Engine revision 0fdb562ac8 • Dart version 2.13.1

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/***/Library/Android/sdk • Platform android-30, build-tools 30.0.3 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.5, Build version 12E262 • CocoaPods version 1.10.1

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] VS Code (version 1.56.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.22.0

[✓] Connected device (2 available) • SM A530F (mobile) • android-arm64 • Android 9 (API 28) • Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.77

geolocator: ^7.0.3

nikhiysham commented 3 years ago

I try set forceAndroidLocationManager to true and its working. Not sure why

Position position = await Geolocator.getCurrentPosition(forceAndroidLocationManager: true);

zs-dima commented 3 years ago

@nikhiysham forceAndroidLocationManager:true does NOT work for my case

anjanpatel79 commented 3 years ago

I try set forceAndroidLocationManager to true and its working. Not sure why

Position position = await Geolocator.getCurrentPosition(forceAndroidLocationManager: true);

This is working. Use: Position position = await Geolocator.getCurrentPosition( forceAndroidLocationManager: true, desiredAccuracy: LocationAccuracy.best, );

florissmit1 commented 3 years ago

I suggest looking at the Geolocator example application. For me it's working fine on Android emulator / Samsung / Oppo test device using flutter 2.2.1. @zs-dima also, you're using an unstable version of Flutter, can you try using a stable version of Flutter?

@sami7568 @zs-dima can you provide a code snippet of the code you're using to get the currentPosition?

no-response[bot] commented 3 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

barbalex commented 3 years ago

I have the exact same problem. It worked yesterday or the day before. Today await Geolocator.getCurrentPosition seems to do absolutely nothing. I changed nothing apart from updating flutter_map.

Why was this closed?

barbalex commented 3 years ago

So I saw that this bot seems more intelligent than expected. I will try to give you more information:

derterminePosition.dart:

import 'package:geolocator/geolocator.dart';

determinePosition() async {
  bool serviceEnabled;
  LocationPermission permission;

  // Test if location services are enabled.
  serviceEnabled = await Geolocator.isLocationServiceEnabled();
  if (!serviceEnabled) {
    // Location services are not enabled don't continue
    // accessing the position and request users of the
    // App to enable the location services.
    return Future.error('Location services are disabled.');
  }

  permission = await Geolocator.checkPermission();
  if (permission == LocationPermission.denied) {
    permission = await Geolocator.requestPermission();
    if (permission == LocationPermission.denied) {
      // Permissions are denied, next time you could try
      // requesting permissions again (this is also where
      // Android's shouldShowRequestPermissionRationale
      // returned true. According to Android guidelines
      // your App should show an explanatory UI now.
      return Future.error('Location permissions are denied');
    }
  }

  if (permission == LocationPermission.deniedForever) {
    // Permissions are denied forever, handle appropriately.
    return Future.error(
        'Location permissions are permanently denied, we cannot request permissions.');
  }

  // When we reach here, permissions are granted and we can
  // continue accessing the position of the device.
  // use getPositionStream for updates
  return await Geolocator.getCurrentPosition();
}

locate.dart:

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'determinePosition.dart';
import 'package:geolocator/geolocator.dart';
import 'package:flutter_map/flutter_map.dart';

class MapMenuLocate extends StatelessWidget {
  final MapController mapController;
  MapMenuLocate({required this.mapController});

  @override
  Widget build(BuildContext context) {
    final toggleButtonsSelected = <bool>[false].obs;

    return Container(
      color: Theme.of(context).primaryColor.withOpacity(0.2),
      child: ToggleButtons(
        children: [
          Tooltip(
              child: Icon(Icons.my_location),
              message: 'Pan to current location'),
        ],
        isSelected: toggleButtonsSelected,
        onPressed: (int index) async {
          print('pressed: $index');
          toggleButtonsSelected[index] = true;
          Timer(
            Duration(seconds: 1),
            () {
              toggleButtonsSelected[index] = false;
            },
          );
          Position? position;
          try {
            position = await determinePosition();
          } catch (e) {
            Get.snackbar(
              'Error accessing position',
              e.toString(),
              snackPosition: SnackPosition.BOTTOM,
            );
          }
          if (position?.latitude != null && position?.longitude != null) {
            mapController.move(
              LatLng(
                position?.latitude ?? 0,
                position?.longitude ?? 0,
              ),
              13,
            );
          }
        },
        direction: Axis.vertical,
        selectedColor: Colors.white,
        fillColor: Theme.of(context).primaryColor.withOpacity(0.5),
        selectedBorderColor: Theme.of(context).primaryColor,
        borderColor: Theme.of(context).primaryColor,
      ),
    );
  }
}

And here the widget that calls MapMenuLocate: (uses ToggleButtons even though it is a single button because this is a group of ToggleButtons and this is the only one with a single button)

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'determinePosition.dart';
import 'package:geolocator/geolocator.dart';
import 'package:flutter_map/flutter_map.dart';

class MapMenuLocate extends StatelessWidget {
  final MapController mapController;
  MapMenuLocate({required this.mapController});

  @override
  Widget build(BuildContext context) {
    final toggleButtonsSelected = <bool>[false].obs;

    return Container(
      color: Theme.of(context).primaryColor.withOpacity(0.2),
      child: ToggleButtons(
        children: [
          Tooltip(
              child: Icon(Icons.my_location),
              message: 'Pan to current location'),
        ],
        isSelected: toggleButtonsSelected,
        onPressed: (int index) async {
          print('pressed: $index');
          toggleButtonsSelected[index] = true;
          Timer(
            Duration(seconds: 1),
            () {
              toggleButtonsSelected[index] = false;
            },
          );
          Position? position;
          try {
            position = await determinePosition();
          } catch (e) {
            Get.snackbar(
              'Error accessing position',
              e.toString(),
              snackPosition: SnackPosition.BOTTOM,
            );
          }
          if (position?.latitude != null && position?.longitude != null) {
            mapController.move(
              LatLng(
                position?.latitude ?? 0,
                position?.longitude ?? 0,
              ),
              13,
            );
          }
        },
        direction: Axis.vertical,
        selectedColor: Colors.white,
        fillColor: Theme.of(context).primaryColor.withOpacity(0.5),
        selectedBorderColor: Theme.of(context).primaryColor,
        borderColor: Theme.of(context).primaryColor,
      ),
    );
  }
}

Do you need more info?

florissmit1 commented 3 years ago

@barbalex Thanks for the extensive information you provided. Your code seems good to me to be honest. Just to be sure, did you add:

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

to your AndroidManifest? And:

<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>

To your info.plist? Also, are you able to provide your flutter doctor -v and which version of geolocator you're using?

barbalex commented 3 years ago

@florissmit1 Yes I did.

It seems to be related with the (configuration of the?) virtual device used. My usually used one crashed yesterday and I started one I use rarely. Here it does not work. Even though a location is set.

I now wiped all user data from the usual one I use which enabled me to restart my app in it again. And now it works.

So it seems to have nothing to do with my code and neither with flutter-geolocator. Sorry for bugging you.

And thanks a lot for giving us this great tool!

fomekong83 commented 3 years ago

Have same issue !! GETTING USER LOCATION

var location = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best,forceAndroidLocationManager: true);

not returning.

flutter doctor -v

[√] Flutter (Channel stable, 2.2.2, on Microsoft Windows [Version 10.0.19042.1052], locale en-US) • Flutter version 2.2.2 at C:\flutter • Framework revision d79295af24 (3 weeks ago), 2021-06-11 08:56:01 -0700 • Engine revision 91c9fc8fe0 • Dart version 2.13.3

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1) • Android SDK at C:\Users***\AppData\Local\Android\sdk • Platform android-30, build-tools 30.0.1 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174) • All Android licenses accepted.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[√] Android Studio • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • android-studio-dir = C:\Program Files\Android\Android Studio • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[√] VS Code (version 1.57.1) • VS Code at C:\Users***\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.14.1

[√] Connected device (2 available)

HERE IS MY CODE

Future _determinePosition() async { bool serviceEnabled; LocationPermission permission;

// Test if location services are enabled.
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
  return Future.error('Location services are disabled.');
}

permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
  permission = await Geolocator.requestPermission();
  if (permission == LocationPermission.denied) {
    return Future.error('Location permissions are denied');
  }
}

if (permission == LocationPermission.deniedForever) {
  // Permissions are denied forever, handle appropriately.
  return Future.error(
      'Location permissions are permanently denied, we cannot request permissions.');
}

var location = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best,forceAndroidLocationManager: true);

return location;

}

THIS IS HOW I CALL IT

FutureBuilder( builder: (context,snapshot){ switch(snapshot.connectionState){ case ConnectionState.waiting: return Text("Loading Location"); default: if (snapshot.hasError) return Text('Error can\'t get your location: ${snapshot.error}'); else return Text('Result: ${snapshot.data}'); } }, future: _determinePosition(), ),

I ADDED THESE INTO MY ANDROID MANIFEST

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

I'M USING geolocator: ^7.2.0+1

MY GRADLE LOOKS LIKE THIS

android { compileSdkVersion 30

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).

    minSdkVersion 20
    targetSdkVersion 30
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

I'M NEW IN THIS . HELP HELP

aozuraa commented 2 years ago

had the same issue. when used on an emulator use an app that fakes location this fixed it for me, the built-in location changer of emulators does not work.

cramble19 commented 2 years ago

had the same issue. when used on an emulator use an app that fakes location this fixed it for me, the built-in location changer of emulators does not work.

Can you please tell where can i get the app from? I am new into these environments and i have not been able to use geolocator in my emulator in few days and its bugging me a lot. No data is returned by await statement

sami7568 commented 2 years ago

Thanks for your email. I have solved it

On Fri, 21 Jan 2022, 6:48 pm cramble19, @.***> wrote:

had the same issue. when used on an emulator use an app that fakes location this fixed it for me, the built-in location changer of emulators does not work.

Can you please tell where can i get the app from? I am new into these environments and i have not been able to use geolocator in my emulator in few days and its bugging me a lot. No data is returned by await statement

— Reply to this email directly, view it on GitHub https://github.com/Baseflow/flutter-geolocator/issues/731#issuecomment-1018519869, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANAUJ6UHRZTH2BUNYN7ZCOTUXFP2BANCNFSM44JN3QYQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

tinvyhx commented 2 years ago

same issue

await Geolocator.getCurrentPosition(forceAndroidLocationManager: Platform.isAndroid);
print('over')
//over not presented;

device sony xperia B8342

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.8.1, on macOS 11.6.1 20G224 darwin-x64, locale zh-Hans-CN) [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2020.3) [✓] VS Code (version 1.64.2) [✓] Connected device (2 available)

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
rodgav commented 2 years ago

activar GPS en genymotion. image

your3i commented 2 years ago

had the same issue, in my case it's because my device was not connected to the internet

reschaefer commented 1 year ago

I had the same problem and since it doesn't show any errors, to solve it I include the method inside a Future.delayed, I determined a duration, and if there is no response, the application continues working normally

EmmanuelO11 commented 1 year ago

Still now resolution for this?

beamlakTadesse commented 1 year ago

I am facing the same issue any resolution?

SunlightBro commented 1 year ago

Reported by user in app that is in production: • EDA71 G (mobile) • 21113B1FCB • android-arm64 • Android 8.1.0 (API 27)

Tested the example app on this exact device, and getCurrentPosition() never returns.

Then did a lot of test with real devices with Android 9 and before:

• EDA71 G (mobile)  • 21113B1FCB         • android-arm64  • Android 8.1.0 (API 27)
• SM G930F (mobile) • 988674424b56494e49 • android-arm64  • Android 8.0.0 (API 26)
• SM G955F (mobile) • ce021712daadea0f02 • android-arm64  • Android 9 (API 28)
sami7568 commented 1 year ago

@SunlightBro use geolocation version 8.0.1, and use this code will work now, I have solved it by using this specific version if you are using latest version or older version, await Geolocator.getCurrentLocation() it may be never returns. also use the solution provided by @nikhiysham

JeroenWeener commented 1 year ago

I have tested the newest version of the plugin (9.0.2), using the example application.

This seems to confirm that Geolocator.getCurrentPosition() is not working on Android devices.

AliEasy commented 1 year ago

Still experiencing this.... This repository is 2 years old

tyanochkuby commented 1 year ago

I have the same issue except that even await Geolocator.isLocationServiceEnabled(); stucks.

No worries, Geolocator.getCurrentPosition() stucks as well

JeroenWeener commented 1 year ago

Today I have tested the example app again (both the example app in geolocator and the example app in geolocator_android). To my surprise, it worked on both iOS and Android.

✅ iPhone 13 emulator (iOS 15.5) ✅ Pixel 5 emulator (Android API 33) ✅ Motorola Moto G8 plus physical device (Android API 29)

It might be a permission issue, where behavior is different depending on the exact permission that is provided by the user (Allow only while using the app vs Ask every time).

mutairibassam commented 1 year ago

@JeroenWeener; thanks for the support.

I want to tell you about my experience while I am using the package which might give you more hints to fix the issue.

First, my use case I want to send user's location every 2 mins in foreground mode and every 15 mins in background mode. getCurrentPosition() is working with fine in foreground mode for both Android and iOS but in background mode always keeps do nothing (waiting for something and never return something at this moment) and keeps adding all the requests once I bring the application to foreground starts triggering all the pending requests at the same time based on last location. This is happening for both Android and iOS.

I switched to use getLastKnownPosition() but always return the same last position which make it pointless for my use case.

below is my configuration:

[✓] Flutter (Channel stable, 3.10.5, on macOS 13.4.1 22F770820d darwin-arm64, locale
    en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.80.1)
[✓] Connected device (3 available)
[✓] Network resources
tyanochkuby commented 1 year ago

Oh yeah. I have pretty much the same issue.. I want to send notification with weather forecast (so obviously I do this task in the background and I need to know user's location). And it's kinda shameful I have to 'lie' to the user that I'm using his location while I am not. Does anyone know what am I supposed to do in this case?

On Sun, Jul 23, 2023, 20:21 Bassam A. @.***> wrote:

@JeroenWeener https://github.com/JeroenWeener; thanks for the support.

I want to tell you about my experience while I am using the package which might give you more hints to fix the issue.

First, my use case I want to send user's location every 2 mins in foreground mode and every 15 mins in background mode. getCurrentPosition() is working with fine in foreground mode for both Android and iOS but in background mode always keeps do nothing (waiting for something and never return something at this moment) and keeps adding all the requests once I bring the application to foreground starts triggering all the pending requests at the same time based on last location. This is happening for both Android and iOS.

I switched to use getLastKnownPosition() but always return the same last position which make it pointless for my use case.

below is my configuration:

[✓] Flutter (Channel stable, 3.10.5, on macOS 13.4.1 22F770820d darwin-arm64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) [✓] Xcode - develop for iOS and macOS (Xcode 14.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.3) [✓] VS Code (version 1.80.1) [✓] Connected device (3 available) [✓] Network resources

  • geolocator: ^8.2.1

— Reply to this email directly, view it on GitHub https://github.com/Baseflow/flutter-geolocator/issues/731#issuecomment-1646896815, or unsubscribe https://github.com/notifications/unsubscribe-auth/AS5QKKGODE4RG6J35UOSBWTXRVMSTANCNFSM44JN3QYQ . You are receiving this because you commented.Message ID: @.***>

TimHoogstrate commented 1 year ago

It seems to work fine on my Android 13 device too. However, we could inform the user when he has switched off the google location service with the same Dialog as we do with the getCurrentPosition() call.

Fubiven commented 8 months ago

have the same problem, " await Geolocator.getCurrentPosition(); " dont return Position, with mobile from OPPO PEMM20, also dont callback from "Geolocator.getPositionStream". and i also find that some OPPO device did not work while 5G been open

HannesVDB commented 8 months ago

Seeing this problem on a couple of different devices:

This is our piece of code.

@override
  Future<LocationTrackingData> getLocation({bool forceRefresh = false, bool useTimeout = true}) async {
    if (!forceRefresh) {
      try {
        if (_hasMergedCurrentPositionStream) return _currentPositionStream.first;
      } catch (e) {
        logger.debug('Failed to get the current location from stream: $e - falling back to getCurrentPosition.');
      }
    }
    Position? position;
    try {
      position = await Geolocator.getCurrentPosition(
        timeLimit: useTimeout ? ThemeDurations.locationFetchTimeout() : null,
      );
    } catch (e) {
      logger.debug('Failed to get current location: $e - falling back to last known location.');
      position = await Geolocator.getLastKnownPosition();
    }

    if (position == null) throw ArgumentError('No location found');
    final location = _getLocationFromPosition(position);
    _currentPositionStream.add(location);
    return location;
  }

Resulting in an ArgumentError

We're now trying to solve this by adding a fallback on the legacy location manager

/// Force the user to fetch the location from the Android Location Manager
    if (position == null && Platform.isAndroid) {
      try {
        position = await Geolocator.getCurrentPosition(
          timeLimit: useTimeout ? ThemeDurations.locationFetchTimeout() : null,
          forceAndroidLocationManager: true,
        );
      } catch (e) {
        logger.debug('Failed to force get current location: $e - falling back to force last known location.');
        position = await Geolocator.getLastKnownPosition(forceAndroidLocationManager: true);
      }
    }

I'll update my response if tests with physical devices give more insights.

ZhupaninGit commented 8 months ago

have the same problem on physical xioami mi t10,on emulator works without any problems

worked on phisical device after adding it to AndroidManifext.xml(don`t works only with ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION)

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permissio.WAKE_LOCK" />
<uses-permission android:name="android.hardware.location.gps" /> 
mohitrajsinha commented 8 months ago

@ZhupaninGit Thanks it worked on my VIVO and XIAOMI.

aly7yaNasser commented 4 months ago

using latest version of geolocator and flutter but can,t get the location after applying this code 'await Geolocator.getCurrentPosition(); '

Thank for this notice it was helpful

Rajaotix commented 1 month ago

I got this issue when I have no internet. But When I put on my internet first then launch getCurrentPosition() it works. But I need to get the device pure location .. someone know how to do that ?Thanks

alladyaditi commented 1 month ago

i am currently facing the same issue with the geolocator version 12.0.0? any body else having the same issue?

aly7yaNasser commented 1 month ago

Use Geolocator.getCurrentPosition(). Then Instead of await Geolocator.getCurrentPosition();