如何可靠是LocationManager的getLastKnownLocation和频率是更新?频率、可靠、LocationManager、getLastKnownLocation

2023-09-06 08:46:56 作者:做个废材继续可爱

我建立一个应用程序,可以在某些操作使用用户的当前位置。位置较的一个好处给用户,而不是过程的一个关键组成部分。我感兴趣的只是非常粗略的准确性,它可以由5甚至10英里被关闭,仍然是有价值的。总体规划是要看到,如果网络提供商启用,然后就去做

I am building an app that can use a user's current location on certain actions. Location is more of a benefit to the user rather than a critical part of the process. I'm only interested in very rough accuracy and it can be off by 5 or even 10 miles and still be of value. General plan was to see if the network provider was enabled and then just do

locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)

假设没有其他应用程序正在运行,将手机会自动定期更新的网络位置?即有可能永远是这个code,这将满足我的需要返回的值?

Assuming that no other apps are running, will the phone automatically periodically update the network location? I.e. there will likely always be a value returned by this code which will meet my needs?

编辑:

我已经做了一点研究,我想这个问题我真的想在这里问了,如果Android操作系统还是手机本身将更新的最后一个已知位置的网络供应商为手机锁定到不同手机天线塔或WiFi网络。答案似乎没有。动力停在我的手机所有的应用程序,我知道交互定位服务后,最后一个已知位置已经停止更新。所以,我猜测,这些天有机会,大多数手机将在后台运行更新的最后一个已知位置的一些位置服务,但手机本身不会去做。因此,我想我会去用某种形式的请求位置更新,如果最后已知位置太旧了。

I've been doing a bit more research and I think the question I was really trying to ask here was if the Android operating system or the phone itself would update the last known location for the network provider as the phone locked onto different cell phone towers or wifi networks. The answer appears to be no. After force stopping all apps on my phone which I know to interaction with location services, the last known location has stopped updating. So, I'm guessing that these days chances are that most phones will have some location services running in the background updating the last known location but the phone itself won't do it. Hence I think I'll be going with some form of requesting location updates if the last known location is too old.

推荐答案

getLastKnownLocation()只返回最后一个修补程序。因此,如果没有位置提供商正在更新getLastKnownLocation的返回值()也不会改变。 location对象还将为您提供精确度和时间修复。

getLastKnownLocation() only returns the last fix. So if no location providers are being updated the return value of getLastKnownLocation() will not change. The location object will also provide you with accuracy and time of the fix.

我想看看这个帖子以获取更多信息。你可以使用一些版本的一杆的位置。

I would look at this post for more information. You could use some version of the one shot location.

http://android-developers.blogspot.com/2011/06/deep-dive-into-location.html