Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

android LocationManager.requestLocationUpdates with minTime >0 not working as expected

I set

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0f, this);

it has an odd behavior, locationChanged gets called every second instead of any time close to 1 minute. Secondly, locationChanged gets called every second for like 10 seconds, then stops completely, the gps satalites icon disappears, then only resumes again when the screen returns from display timeout.
what's wrong?

I'm currently on android 1.5.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The minTime (60000) is just a hint, and there's no guarantee that your locationlistener will kick in at an exact 1 minute interval. Combined with the minDistance=0, you'll probably receive a lot more updates.

I would increase the minDistance to 1m minimum, and implement compensation logic to achieve the 1 minute interval in your code. You LocationListener can be implemented in such a way that if location updates follow too closely, they are ignored and not processed.

You'll also get different locations through your location listener, with a different accuracy, all within that minute interval.

Your location listener can pick the best accuracy, and remember when the last location was processed by maintaining state (lastLocationProcessedAt).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...