我正在构建一个可以在某些操作上使用用户当前位置的应用.位置对用户更有利,而不是流程的关键部分.我只对非常粗略的准确性感兴趣,它可能会偏离 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)
假设没有其他应用在运行,手机会自动定期更新网络位置吗?IE.此代码可能总是会返回一个满足我需要的值?
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() 的返回值不会改变.位置对象还将为您提供修复的准确性和时间.
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
这篇关于LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!