位置为空 - 与真实设备中的行为相同吗?
嘿伙计们,就我没有真正的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.