位置服务' `getLastKnownLocation()`查看手机目前的GPS位置?

时间:2015-08-23 00:47:39

标签: android gps geolocation

有些资源说getLastKnownLocation()只是提供了之前某个应用的位置变更监听器的位置。

但是我觉得有一件事在对话中丢失了 - 如果手机启用了GPS,那么当手机移动时,GPS跟踪/更新是不是?因此,如果我拨打getLastKnownLocation(),是不是从手机不断更新的GPS中获取了当前的GPS?

如果是这样,那么为什么人们会警告不要使用它/指责它可能会导致过时的#34;地点?如果正在跟踪/更新GPS,getLastKnownLocation()一次性抓住它的当前位置,那么getLastKnownLocation()是什么造成的?

我对Locations服务或GPS有什么误解?

2 个答案:

答案 0 :(得分:2)

documentation说:Returns a Location indicating the data from the last known location fix obtained from the given provider.

此外,关于“过时的位置”:This can be done without starting the provider. Note that this location could be out-of-date, for example if the device was turned off and moved to another location.(“此”指的是获取最后的已知位置)。

另外,取自LocationProvider docsEach provider has a set of criteria under which it may be used; for example, some providers require GPS hardware and visibility to a number of satellites; others require the use of the cellular radio, or access to a specific carrier's network, or to the internet. They may also have different battery consumption characteristics or monetary costs to the user.

  

如果手机启用了GPS,那么当手机移动时,GPS跟踪/更新不是吗?

嗯,这是,但不是经常。这与电池消耗有关,如果手机不断更新GPS位置,电池寿命会受到很大影响。当某些应用程序请求时,GPS位置通常会更新。但即使这个要求也不能保证成功。例如,假设您进入隧道。一些应用程序请求在进入隧道之前更新GPS坐标并且成功。现在,你进入了5公里长的隧道。很可能你的设备无法从隧道中获得GPS修复,因此对于接下来的5公里(至少)getLastKnownLocation()将返回一个过时的值,因为设备上次已知位置位于隧道入口

您可以做的是明确要求更新GPS位置,但这可能需要一些时间,并且无法保证它会成功。

答案 1 :(得分:1)

您假设“如果手机启用了GPS,那么随着手机移动,这不是GPS跟踪/更新”。这个假设是不正确的。 GPS功能占用了大量的电池,因此应该谨慎使用,几乎肯定不会一直使用。

相关问题