location is null - is it the same behavior in real device?

梦想的初衷 提交于 2020-01-16 13:28:44

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/4474470/location-is-null-is-it-the-same-behavior-in-real-device

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