位置是空 - 它是在实际设备相同的行为? [英] location is null - is it the same behavior in real device?
问题描述
据我没有真正的Android手机我想问这个问题。
在我MapActivity这是从LocationListener的延长,onCreate方法初始化位置元素如下:
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);
当我开始我的应用程序,该位置始终空,直到我从DDMS送分。
我想知道,在实际的设备会是什么行为?
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?
推荐答案
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.
如果你想获得的实际位置,你需要设置一个LocationListener的。
If you want to get the actual location, you need to set up a locationlistener.
这篇关于位置是空 - 它是在实际设备相同的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!