位置为空 - 与真实设备中的行为相同吗?

发布于 2024-10-08 01:02:46 字数 258 浏览 0 评论 0原文

嘿伙计们,就我没有真正的 Android 手机而言,我想问这个问题。 在从 LocationListener 扩展的 MapActivity 中,onCreate 方法初始化“location”元素如下:

location = locationManager.getLastKnownLocation(provider);

当我启动应用程序时,位置始终为 null,直到我从 DDMS 发送点。 我想知道,在真实设备中会出现什么行为?

Hey guys as far as i don't have real android phone I wanted to ask this question.
in my MapActivity which is extended from LocationListener, the onCreate method initializes "location" element as following :

location = locationManager.getLastKnownLocation(provider);

When I start my app, the location is always null until I send points from DDMS.
I wanted to know, in real device what would be the behavior?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℡寂寞咖啡 2024-10-15 01:02:46

getLastKnownLocation() 仅获取 GPS 最后返回的位置。如果 GPS 从未获得位置修复,则它将为空。您根本不能指望此方法返回值,如果返回值,则可能已经非常过时了。

如果你想获取实际位置,你需要设置一个位置监听器。

getLastKnownLocation() only gets the location last returned by the GPS. If the gps has never gotten a location fix, it will be null. You can't count on this method returning a value at all, and if it does it might be extremely out of date.

If you want to get the actual location, you need to set up a locationlistener.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文