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