[Bug]: Infinity getting current location
Please check the following before submitting a new issue.
- [x] I have searched the existing issues.
- [x] I have carefully read the documentation and verified I have added the required platform specific configuration.
Please select affected platform(s)
- [x] Android
- [ ] iOS
- [ ] Linux
- [ ] macOS
- [ ] Web
- [ ] Windows
Steps to reproduce
- I use Android emulator with Android 15 device
- Geolocator package version is ^12.0.0
- Flutter version is 3.19.6
- I open the app and choose "Only this time"/"While using the app"
- Bug reproduces rarely and currently it is noticed only on newer Android versions(for example Android 15)
Expected results
I expect location to be determined without any problems.
Actual results
Application loads infinitely since the location can not be determined. Location pin icon in phone header stays forever.
What could cause this problem and how can it be solved? Is someone else facing it and are there any exact steps to reproduce? Is the problem reproducing in newer Geolocator versions?
Code sample
Code sample
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.best);
</details>
### Version
^12.0.0
### Flutter Doctor output
<details><summary>Doctor output</summary>
```console
[!] Flutter (Channel [user-branch], 3.19.6, on Microsoft Windows [Version 10.0.26100.3775], locale bg-BG)
! Flutter version 3.19.6 on channel [user-branch] at C:\flutter
Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
! Upstream repository unknown source is not a standard remote.
Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
• Framework revision 54e66469a9 (1 year, 1 month ago), 2024-04-17 13:08:03 -0700
• Engine revision c4cd48e186
• Dart version 3.3.4
• DevTools version 2.31.1
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc3)
• Android SDK at C:\Android
• Platform android-35, build-tools 35.0.0-rc3
• Java binary at: C:\Program Files\Android\Android Studio1\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 21.0.6+-13355223-b631.42)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[!] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.5)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.11.35327.3
X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these
components:
MSVC v142 - VS 2019 C++ x64/x86 build tools
- If there are multiple build tool versions available, install the latest
C++ CMake tools for Windows
Windows 10 SDK
[√] Android Studio (version 2024.3)
• Android Studio at C:\Program Files\Android\Android Studio1
• 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 21.0.6+-13355223-b631.42)
[√] VS Code (version 1.93.1)
• VS Code at C:\Users\Stoyan Kirov\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.110.0
[√] Connected device (4 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 15 (API 35) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.26100.3775]
• Chrome (web) • chrome • web-javascript • Google Chrome 135.0.7049.115
• Edge (web) • edge • web-javascript • Microsoft Edge 136.0.3240.50
[√] Network resources
• All expected network resources are available.```
</details>
Dear @stoyankirov,
Can you add the settings that you use to this issue? Also try to investigate if this also happens in the example app that is available when you clone the repository.
Kind regards,
@TimHoogstrate do you mean the permission settings? If so here are the permissions added:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
As said before the problem is reproduced currently only on newer Android versions. On Android version 13 it was never reproduced during the last 6 months of actively using Geolocator for our application and testing it.
Dear @stoyankirov,
Thanks for your reply, I mean the Settings in the code that you use to fetch the locations. Similar to:
final LocationSettings locationSettings = LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 100,
);
Position position = await Geolocator.getCurrentPosition(locationSettings: locationSettings);
Kind regards,
@TimHoogstrate I have mentioned them above in the code sample, they are as follows:
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best);
Dear @stoyankirov,
It means that the OS is unable to determine a location. The location is fetched using Wifi, cellular en gps data, and combined (as efficient as possible) by the OS. Could you perhaps try to run a little test with a real device and outside to see if a location can be determined? It could very well depend on the current device used, because a device could lack a simcard or wifi connection. Therefore, try to use a real device, an emulator is very unreliable regarding positions because it lacks a gps chip and location functions.
Kind regards,
Hi team,
i also see this issue on our side.
await Geolocator.getCurrentPosition(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.medium,
timeLimit: Duration(seconds: 20),
),
);
it stuck in the long loading and then time out after 20 second( which is time limit) also sometimes i try to get it frequently, i get :
D/permissions_handler(26103): No permissions found in manifest for: []25
although i have the permission.
i see it in real devices, both android and ios.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
using last version:
geolocator: ^14.0.0
Dear @TimHoogstrate ,
we have been testing the case for a while and the bug was once reproduced on real device with Android version 14, not only on emulators. Unfortunately the bug does not persist regularly, it is working as expected in the most cases and we can not provide more details or actual steps to reproduce.
@Samin-roadsurfer,
Could you create a new issue? With clear steps to reproduce and the contents of flutter doctor -v?
Kind regards,
Hi @TimHoogstrate ,
I have an update - the bug reproduced several times on emulator even when Timelimit is set:
Position position = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.best, timeLimit: const Duration(seconds: 10));
@stoyankirov,
Is it also reproducible on a real device? Because it is possible (for many reasons) that the emulator crashes.
Kind regards,
@TimHoogstrate yes, it was reproduced several times on Android device.
I am also facing same issue, I have putted my phone on mobile stand , still i am getting frequent location.
Same issue, Android 10. Real device.
Same issue in IOS and Android.
Hi @TimHoogstrate ,
I have an update - the bug reproduced several times on emulator even when Timelimit is set:
Position position = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.best, timeLimit: const Duration(seconds: 10));
In recent versions of the plugin, the timeLimit property should be passed as part of the LocationSettings, and it's used simply to timeout(...) the future call, like this:
https://github.com/Baseflow/flutter-geolocator/blob/756b8d8015f06ecfcc64b438f71cb3b362b5e350/geolocator_android/lib/src/geolocator_android.dart#L112-L124
If you prefer not to delegate the timeout logic to the plugin you can handle it by your own. I just started experiencing this same issue now, on Emulator, and the way I handled it is like this.
Position position = await Geolocator.getCurrentPosition(
locationSettings: LocationSettings(
accuracy: LocationAccuracy.best,
),
).timeout(const Duration(seconds: 10))
Using the latest version (14.0.2) and passing only the
localSettings = AndroidSettings( accuracy: LocationAccuracy.best, // other values );
works, the getCurrentPosition completes on Android 10, physical device.