flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

Android Pie (API 28) Geolocator().getCurrentPosition() does not return

Open savjolovs opened this issue 8 years ago • 40 comments

🐛 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

savjolovs avatar Nov 01 '18 23:11 savjolovs

mee too, whats wrong? :(

5lineofcode avatar Nov 05 '18 03:11 5lineofcode

Same here!

HerrNiklasRaab avatar Nov 08 '18 19:11 HerrNiklasRaab

@savjolovs if I debug, the debugger stops on the Geolocator().getCurrentPosition(). Breakpoints after the mehtod are not getting hit. Can you confirm this behaviour?

HerrNiklasRaab avatar Nov 08 '18 19:11 HerrNiklasRaab

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.

yostrokon avatar Nov 14 '18 12:11 yostrokon

+1 here

ChangJoo-Park avatar Nov 14 '18 13:11 ChangJoo-Park

Anyone an idea whats the cause? This feature is breaking everything, did anyone tried another plugin?

HerrNiklasRaab avatar Nov 14 '18 13:11 HerrNiklasRaab

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 avatar Nov 14 '18 13:11 ibrierley

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

yostrokon avatar Nov 14 '18 15:11 yostrokon

Same issues on Android oreo except you close and open the app again

solnsumei avatar Nov 14 '18 16:11 solnsumei

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.

  1. 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).

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

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

  1. 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 :/.

ibrierley avatar Nov 14 '18 16:11 ibrierley

Thanks @ibrierley for your information, will try as soon as possible and report about my experience solving the issue.

HerrNiklasRaab avatar Nov 15 '18 11:11 HerrNiklasRaab

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.

yostrokon avatar Nov 15 '18 11:11 yostrokon

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.

HerrNiklasRaab avatar Nov 15 '18 19:11 HerrNiklasRaab

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 .

ibrierley avatar Nov 15 '18 20:11 ibrierley

Anyone try mine? flutter_background_geolocation

christocracy avatar Nov 15 '18 20:11 christocracy

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 .

ibrierley avatar Nov 15 '18 20:11 ibrierley

It works even if you terminate your app (stopOnTerminate: false) or reboot the device (startOnBoot: true).

christocracy avatar Nov 15 '18 20:11 christocracy

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?

AbdulrazakZakieh avatar Nov 20 '18 03:11 AbdulrazakZakieh

Same happen, getCurrentPosition does not work using API 23. Any work around for this or any alternative package working for getting current posiiton?

iambudi avatar Dec 21 '18 06:12 iambudi

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.

iambudi avatar Dec 21 '18 08:12 iambudi