Flutter-geolocator: getCurrentPosition not returning device's current position but last queried location

Created on 9 Aug 2019  路  13Comments  路  Source: Baseflow/flutter-geolocator

馃悰 Bug Report


Use getCurrentPosition to get device's current position

Expected behavior

it returns the device's current physical position.

Reproduction steps

it returns the last queried gps position. For example, if I use google maps app to locate my current position in my workplace, and then go home without querying any gps location, and then in my home, I use this plugin's getCurrentPosition API, it returns my workplace's location, not my home's.
This seems to be android only.

Configuration

final Geolocator geolocator = Geolocator();
  geolocator.forceAndroidLocationManager = true;
  return await geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);

Version: 1.x
5.1.1+1
Platform:

  • [ ] :iphone: iOS
  • [x] :robot: Android
android triage

Most helpful comment

Apperently this fixed the issue for me but I am not sure about the implications so use it at your own risk.
Go to the folder (your version may be differente for example: 5.1.3):
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\geolocator-5.1.2\android\src\main\java\com\baseflow\geolocator\tasks

open the file:
LocationUpdatesUsingLocationManagerTask.java

and in the line 70 change:
mBestLocation = locationManager.getLastKnownLocation(mActiveProvider);
to
mBestLocation = null;

All 13 comments

Forgot to mention. If I call getCurrentPosition multiple times in my home, I always get my workplace's location. Only after I use an app like google maps to get my current position, getCurrentPosition returns the correct location.

I am getting the same behavior.

Similar behavior with me as well. Any fix to this?

Apperently this fixed the issue for me but I am not sure about the implications so use it at your own risk.
Go to the folder (your version may be differente for example: 5.1.3):
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\geolocator-5.1.2\android\src\main\java\com\baseflow\geolocator\tasks

open the file:
LocationUpdatesUsingLocationManagerTask.java

and in the line 70 change:
mBestLocation = locationManager.getLastKnownLocation(mActiveProvider);
to
mBestLocation = null;

The same problem with getPositionStream

Have the same reports from numerous users of my application. Reproduced on my Pixel 3XL Android 10 when I don't use any other application that requires gps location for a long time.

Same issue waiting for a fix.

Fix by @n0tc0ding results in #338

Do we have a fix for this? I got a huge number of users reporting this problem

Now I change to 4.0.3, I have no problem.

Now I change to 4.0.3, I have no problem.
@hangridwangyu
I used it but still have same issue

I think no solution will be here to fix that.

We have just released version 6.0.0 of the Geolocator which should have solved this issue.

Was this page helpful?
0 / 5 - 0 ratings