当前位置: 动力学知识库 > 问答 > 编程问答 >

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

问题描述:

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.

网友答案:

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

So that can happen quite often.

网友答案:

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.

网友答案:

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

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: