Android: How often does getLastKnownLocation(LocationManager.NETWORK_PROVIDER) return null in real life?

久未见 提交于 2019-12-02 11:06:21

问题


Do the Android users have the chance to reset the NetworkProvider, so that the location will be null? I came up with the idea, that its only possible to have that location null, after starting the device the very first time. But also than google will check the location right away for my opinion.

Sure, I'm implementing a default location for this rare case. I just want to know how seldom this case is.


回答1:


It returns 'null', when the Service is disabled in Settings > Location and Security > location through network

So that can happen quite often.




回答2:


Depends how frequently connects the user to the Internet.

The cell ids have to be translated to a coordinate, and as I know there is a cache, it will remember even when offline the cell ids already translated, but on new ones, it won't give you location updates until the phone it's not connected to Internet.

Anyway, you always needs to check the date of the location, as it might be outdated. Especially after you put your phone in airplane mode and travel to the other part of the world.




回答3:


In my testing I've found it's null fairly often. Not a lot of things consume the GPS without the user telling them to. But the problem with getLastKnownLocation is that it can be extremely out of date. So even if it's not null, it could be hours or even days old




回答4:


It will probably also depend on how often you are polling it. That is, it could get set to null and stay there a while if you're not checking it frequently.

locationManager.requestLocationUpdates(provider, minTime, minDistance, this);

I had borrowed a project as a skeleton for a mapActivity project. It was return null all the time (with a gps provider) until i inserted the requestLocationUpdates() call.



来源:https://stackoverflow.com/questions/3682998/android-how-often-does-getlastknownlocationlocationmanager-network-provider-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!