android getlastknownlocation returns null

匿名 (未验证) 提交于 2019-12-03 02:14:01

问题:

I know there's a few questions about this, but I'm not finding exactly the answer I want.

I'm calling getLastKnownLocation for the GPS provider and it's returning null. The docs say this might happen if the provider isn't enabled, but I know it is. Is it possible for the provider to return null if no last known location exists? I don't see where the docs say "may return null if no last known location exists"

Thanks!

回答1:

Is it possible for the provider to return null if no last known location exists?

Yes. In fact, much of the time, it will return null, because nothing is causing GPS to acquire fixes. GPS is usually powered down to save on battery life. See Obtaining User Location for the recipe for finding your location.

I don't see where the docs say "may return null if no last known location exists"

The documentation has its flaws.



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