I'm using Flutter SDK 3.19.1 and geolocator: ^9.0.2 to get the current position. It actually works, but the method is slow, it takes about 4 seconds.
await Geolocator.getCurrentPosition();
How can I avoid that time?
I tried to constantly get the current position, this reduces the time to 1 sec, but this way trades a faster execution time with higher battery consumption.
My goal is to get the current position only once in the fastest execution time.
I'm using Flutter SDK 3.19.1 and geolocator: ^9.0.2 to get the current position. It actually works, but the method is slow, it takes about 4 seconds.
await Geolocator.getCurrentPosition();
How can I avoid that time?
I tried to constantly get the current position, this reduces the time to 1 sec, but this way trades a faster execution time with higher battery consumption.
My goal is to get the current position only once in the fastest execution time.
Share Improve this question asked Jan 18 at 13:41 Alex Maglio Neyra HerradaAlex Maglio Neyra Herrada 111 bronze badge1 Answer
Reset to default 1Determining the user's current position takes time and uses power. Nothing you can do in your code can change anything about that, so you will have to deal with both.
A suggested approach here is to first use getLastKnownPosition
to get an initial estimated location quickly and then update with getCurrentPosition
when that returns a value.
The last known position may be wildly off from the current position, but at least you'll have a starting point. And many users are familiar with this behavior where the maps app at first shows the location where they last used it.