最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

geolocation - Getting current position in Flutter is slow - Stack Overflow

programmeradmin0浏览0评论

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 badge
Add a comment  | 

1 Answer 1

Reset to default 1

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

发布评论

评论列表(0)

  1. 暂无评论