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

getLastKnownPosition returns null even if location previously queried before.

Open ghost opened this issue 7 years ago • 2 comments

🐛 Bug Report

From the documentation, my expectation for the .getLastKnownPosition() method is that it will fetch the last valid geolocation that has been previously queried. I tested this out by first getting a working geo location, and turning off the location sensor, and hot restarting the application. The method returns null every time.

The same behaviors exhibited in the sample application.

I am unsure if this is expected behavior since being able to query the last known good location means that the geocoordinates to have be stored somewhere persistent in memory and I do not have the foreknowledge if the application or Android does that. Please correct me if I'm wrong.

Expected behavior

getLastKnownPosition() should provide the last known good geocoordinates that can be retrieved regardless of sensor status.

Reproduction steps

  1. Run the example application.
  2. Turn on location settings and enable application permission.
  3. Retrieve coordinates.
  4. Turn off location sensor.
  5. Hot restart application.

Configuration

Version: 5.0.0

Platform:

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

ghost avatar Jun 15 '19 17:06 ghost

Hey Carrein,

I looked at this issue and according to the Android API this is correct. If you turn off the location service the cache will be cleared, so we can't read this from the memory. See this link for more info: https://developer.android.com/training/location/retrieve-current#last-known

ChiefMax avatar Jul 16 '19 09:07 ChiefMax

@Carrein image like this

rolends1986 avatar Jul 18 '19 00:07 rolends1986