問題描述
我正在構(gòu)建一個可以在某些操作上使用用戶當(dāng)前位置的應(yīng)用.位置對用戶更有利,而不是流程的關(guān)鍵部分.我只對非常粗略的準(zhǔn)確性感興趣,它可能會偏離 5 甚至 10 英里,但仍然很有價值.一般計劃是查看網(wǎng)絡(luò)提供商是否已啟用,然后就這樣做
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)
假設(shè)沒有其他應(yīng)用在運行,手機會自動定期更新網(wǎng)絡(luò)位置嗎?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?
我一直在做更多的研究,我認(rèn)為我在這里真正想問的問題是,Android 操作系統(tǒng)或手機本身是否會更新網(wǎng)絡(luò)提供商的最后一個已知位置,因為手機鎖定到不同的位置手機信號塔或 wifi 網(wǎng)絡(luò).答案似乎是否定的.在強制停止我的手機上我知道與位置服務(wù)交互的所有應(yīng)用程序后,最后一個已知位置已停止更新.所以,我猜現(xiàn)在大多數(shù)手機都有可能在后臺運行一些定位服務(wù)來更新最后一個已知的位置,但手機本身不會這樣做.因此,如果最后一個已知位置太舊,我想我會采用某種形式的位置更新請求.
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() 只返回最后的修復(fù).因此,如果沒有更新位置提供程序,則 getLastKnownLocation() 的返回值不會改變.位置對象還將為您提供修復(fù)的準(zhǔn)確性和時間.
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
這篇關(guān)于LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!