問題描述
LocationManager locationManager = (LocationManager)getApp().getSystemService(Context.LOCATION_SERVICE); //getApp() returns my Application object
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER , 1, 1, this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 1, this);
這就是我用來收聽的代碼.啟用 GPS 后,一切正常.但是,如果我禁用 GPS 并依賴網絡位置,它會給我帶來陳舊的結果——在這種情況下,是兩天前的結果.我無法讓它更新.調用 getLastKnownLocation 會返回相同的陳舊結果.
That's the code I'm using to listen. With GPS enabled, everything works fine. However, if I disable GPS and rely on network location, it gives me stale results -- in this case, from two days ago. I cannot get it to update. Calling getLastKnownLocation returns the same stale results.
Google 地圖更新正常,所以我知道這不是硬件/系統配置問題.
Google Maps updates just fine, so I know it's not a hardware/system configuration problem.
我在 Google 上四處搜索,發現一些人有類似的問題,但沒有答案.我嘗試將我的項目定位到 API 級別 8 (2.2) 和 15 (4.0.3).結果相同.我的手機正在運行 ICS.
I've Googled around, and found a few people with similar problems, but no answers. I've tried targeting my project to API level 8 (2.2) as well as 15 (4.0.3). Same results. My phone is running ICS.
我還嘗試刪除對 GPS_PROVIDER 的請求,以及在 getAllProviders() 中包含對所有內容的請求.同樣的交易.
I've also tried removing the request for GPS_PROVIDER, as well as including requests for everything in getAllProviders(). Same deal.
知道為什么 NETWORK_PROVIDER 沒有更新嗎?任何幫助將不勝感激.
Any idea why NETWORK_PROVIDER is not updating? Any help would be greatly appreciated.
(附注:不,我通常不使用1, 1"作為時間/距離參數;我只是在調試時更改了它.)
(P.S. No, I don't I normally use "1, 1" as my time/distance parameters; I just changed it while debugging this.)
我忘了說是的,isProviderEnabled() 返回 true.
I forgot to mention that yes, isProviderEnabled() returns true.
推薦答案
我終于找到了解決這個問題的方法(見 我的問題在這里).
I finally found a way to solve this problem (see my question here).
在我的 S3 Galaxy Mini 上,有類似的癥狀(在重新啟動之前沒有位置更新......),就像上面描述的那樣.大多數情況下,當設備達到低電量條件時,位置信息就會停止更新,但有時即使手機充滿電,也會發生這種情況.顯然這是 LocationManager
中某處的問題.我設法通過使用新的 Google Play 服務 API 來繞過 LocationManager
位置(LocationClient
類).
In my case on S3 Galaxy Mini there were similar symptoms (no location updates until reboot...) like the ones described above. Location in most cases stopped updating when the device reached low power conditions, but sometimes it just happened even when the phone was fully charged.
Obviously this is a problem somewhere in the LocationManager
. I managed to bypass LocationManager
by using the new Google Play Services API for locations (LocationClient
class).
這可能是位置更新仍然適用于 Google 地圖的原因,因為 Google 地圖甚至在公開之前就使用了 Google Play Services API.
This is probably the reason why the location updates were still working with Google Maps, because Google Maps were using Google Play Services API even before it was made public.
我建議您關注 此鏈接如果遇到此問題,如何使用 Play Services API 獲取位置,而不是使用 LocationManager
.
I recommend you to follow this link which shows the way how to use Play Services API to get locations instead of using LocationManager
if you encounter this problem.
我正在使用 Play Services 運行位置更新,并且絕對沒有這樣的問題 - 我隨時都會收到定期的位置更新.
Im running location updates with Play Services and there were absolutely no problems like this anymore - I keep receiving regular location updates anytime.
請注意,這將要求用戶必須在其設備上安裝 Google Play,因此 Kindle 等設備將無法使用.它還需要至少 Android 2.2.
Beware that this will require that the user must have Google Play installed on their device, so Kindles and the like will be out of the picture. It also requires a minimum of Android 2.2.
這篇關于NETWORK_PROVIDER 未提供更新的位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!