Android LocationManager.getLastKnownLocation()
来自android文档LocationManager.getLastKnownLocation(): 返回一个位置,该位置指示来自最后一个已知位置的数据 从给定提供程序获取的修复程序Android LocationManager.getLastKnownLocation(),android,Android,来自android文档LocationManager.getLastKnownLocation(): 返回一个位置,该位置指示来自最后一个已知位置的数据 从给定提供程序获取的修复程序 Note that this location could be out-of-date, for example if the device was turned off and moved to another location. 提供商多久更新一次设备位置?它是如何工作的 我问的原因是我不想使用locati
Note that this location could be out-of-date, for example if the device was turned off and moved to another location.
提供商多久更新一次设备位置?它是如何工作的
我问的原因是我不想使用locationListener,
我只需要点击按钮就可以得到当前的地理位置,就这样。
我可以这样做吗
final LocationManager mlocManager = (LocationManager) getActivity()
.getSystemService(Context.LOCATION_SERVICE);
final Location currentGeoLocation = mlocManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
提供商多久更新一次设备位置?它是如何工作的
这要看情况,你可能永远也不知道。如果设备接收效果良好,则有关用户位置的更新将迅速启动
我可以这样做吗
final LocationManager mlocManager = (LocationManager) getActivity()
.getSystemService(Context.LOCATION_SERVICE);
final Location currentGeoLocation = mlocManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
不是真的。如果发射太快,你将无法获得任何位置。如果用户没有很好的接收效果,那么可能需要10秒钟的时间,你才能对用户的位置有一个合理的想法。我想你得稍微改变一下。恐怕我必须推荐locationListeners:P
如果您绝对不能等待某个位置,您可以尝试
getLastKnownLocation()
,但您需要准备获得NULL
结果
getLastKnownLocation()
只是您指定的提供程序的最后一个位置的缓存。在某些情况下根本就不会有,比如当手机刚刚重启时。即使存在缓存位置,也可能不准确