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 未提供更新的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!