Android Pie (API 28) Geolocator().getCurrentPosition() does not return
🐛 Bug Report
When I run Geolocator().getCurrentPosition() on Android Emulator with Android Pie (API 28) call is not returning at all.
I run the same code on API 27 location returns fine. I tried to create new emulator, nothing changes.
Configuration
Android Emulator with Android Pie (API 28)
Version: 2.1.0
Platform:
- [ ] :iphone: iOS
- [X ] :robot: Android
mee too, whats wrong? :(
Same here!
@savjolovs if I debug, the debugger stops on the Geolocator().getCurrentPosition(). Breakpoints after the mehtod are not getting hit. Can you confirm this behaviour?
Same behaviour here till push some coordinates using extended controls. Same behaviour with one of two phisycal devices. First with android 5 - works fine, another with 6 - no response till fakegps location engaged.
+1 here
Anyone an idea whats the cause? This feature is breaking everything, did anyone tried another plugin?
Checking the obvious, for those with the problem, do you have a gps signal for it to get a location and have moved ? Just wondering if it's sat there waiting for some new location before it updates ?
@ibrierley seems like can't get GPS signal with or without moving, but at the same time different apps like google maps have no problems to locate current position. lastKnownPosition returns location for about couple hundred meters far away. With android 5 don't have problems at all, even not asked for the location permission (but not sure, may be i missed this at debug)
Same issues on Android oreo except you close and open the app again
I've been fiddling with an Android Wear watch and had a lot of problems with GPS, but I seem to have it working mostly (it can time out after a long time, but I think that's a different issue).
I'm not sure what exactly has got it working, as I've tried lots of things, but maybe someone can check these off and see if they help.
-
Make sure your device can get a GPS signal, so outside or feed it locations via the emulator (I feed it a GPX route I downloaded to test).
-
Make sure the screen is on. GPS may stop returning results if it's in minimal mode whatever it's called. I force the screen on when needed with Screen package and Screen.keepOn(true); If the screen is off, it seems to hold and buffer a set of locations until the screen is back on.
-
These are my permissions in AndroidManifest.xml, maybe worth a try
<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.permission.WAKE_LOCK" /> <uses-permission android:name="android.hardware.location.gps" />
Note especially the very last one, as I think there was a change along the way in one version, and it seemed to help. You may not want the wake_lock for battery reasons, but it may be useful to try this to eliminate where the problem is.
- I had oddities with the Stream timing out, so I ended up starting the stream with geolocator.getPositionStream but not actually using it. With the stream running, I'm calling getCurrentPosition( desiredAccuracy: LocationAccuracy.high ) based on a timer. I think this isn't needed now, as I think my original problem was the screen being off, but it may be worth trying just out of interest.
If someone tries the above and can't get it working, can you create a minimal flutter app, just with the location stuff, and I'll see if it fails the same on mine. It is a lot more painful to get going than it should :/.
Thanks @ibrierley for your information, will try as soon as possible and report about my experience solving the issue.
Did some research today with an additional tools like GPS test on physical devices. So there is no response when sat is not available by GPS test (0 connected 1 available because of clouds and big buildings around) even google map or other map services are works. No response when sat is online but defined distance in location options, but not 100% in this case - need some kind of gps drift to have an initial coordinates. I did some trick with lastknownlocation to position over there to initiate app that require current location before actual location data available. Probably would be a great solution to have some kind of flag like isReady with possible callback in the Geolocator that indicate is GPS service is ready to offer location data through stream.
Has anyone tried for example this: https://github.com/Lyokone/flutterlocation, or this: https://github.com/Lyokone/flutterlocation ? So we can exlude errors that are not related to this package.
I've tried that, and ended up with this one (that's not to say it's not worth a try though!). All of them have 'some' problems, I think really because Android has some things that aren't obvious.
Typically I've found when a location doesn't get returned on any of the packages), it's because of a none-flutter issue (eg the gps has gone into sleep mode, or no gps signal).
On Thu, Nov 15, 2018 at 7:26 PM HerrNiklasRaab [email protected] wrote:
Has anyone tried for example this: https://github.com/Lyokone/flutterlocation, or this: https://github.com/Lyokone/flutterlocation ? So we can exlude errors that are not related to this package.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BaseflowIT/flutter-geolocator/issues/135#issuecomment-439160446, or mute the thread https://github.com/notifications/unsubscribe-auth/ADuG9WRbZuJYvi5N_2xrrku-Jurk6trIks5uvb_SgaJpZM4YKDSm .
Anyone try mine? flutter_background_geolocation
Does it work with the screen off out of interest ?
On Thu, Nov 15, 2018 at 8:16 PM Chris Scott [email protected] wrote:
Anyone try mine? flutter_background_geolocation https://pub.dartlang.org/packages/flutter_background_geolocation#-readme-tab-
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BaseflowIT/flutter-geolocator/issues/135#issuecomment-439175841, or mute the thread https://github.com/notifications/unsubscribe-auth/ADuG9f5uvZK0lDnYecMoFZhJnF0ylz6Pks5uvcuygaJpZM4YKDSm .
It works even if you terminate your app (stopOnTerminate: false) or reboot the device (startOnBoot: true).
I am facing the same problem, which is never returning from getCurrentPosition.
I have the following code:
position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.best);
setState(() {
_position = position;
});
if (position == null)
Fluttertoast.showToast(
msg: 'Position is null', toastLength: Toast.LENGTH_SHORT);
else
Fluttertoast.showToast(
msg: 'Got Position', toastLength: Toast.LENGTH_SHORT);
The permissions are:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.hardware.location.gps" />
<uses-permission android:name="android.hardware.location.network" />
<uses-permission android:name="android.permission.WAKE_LOCK" />.
When I run the program, the location indicator appears on the top on the screen and stay still until I close the program.
Any help, please?
Same happen, getCurrentPosition does not work using API 23. Any work around for this or any alternative package working for getting current posiiton?
It's a bit tricky. I could make it work now by launching Google Map app first and let it ask for permission to enable GPS when tap my location. After that getCurrentPosition suddenly work like a charm.