定位服务的“getLastKnownLocation()”是否检查 phone 的当前 GPS 位置?
Does Location Services' `getLastKnownLocation()` check phone's current GPS location?
一些资源说 getLastKnownLocation()
仅仅给出了一些以前应用的位置变化监听器的位置。
但是我觉得谈话中遗漏了一件事——如果 phone 启用了 GPS,那么 phone 移动时这个 GPS tracking/updating 不是吗?所以如果我调用 getLastKnownLocation()
,它不是从 phone 不断更新的 GPS 获取当前 GPS 吗?
如果是这样,那么为什么人们警告不要使用它/指责它可能获得 "stale" 位置?如果 GPS 正在被跟踪/更新,并且 getLastKnownLocation()
一次性获取了它的当前位置,那么 getLastKnownLocation()
不好的原因是什么?
我对 Locations
服务或 GPS 有什么误解?
你有假设 "if the phone has GPS enabled, isn't this GPS tracking/updating as the phone moves"。这个假设是不正确的。 GPS 功能会占用大量电池寿命,因此应谨慎使用,而且几乎肯定不会一直使用。
documentation 说:Returns a Location indicating the data from the last known location fix obtained from the given provider.
另外,关于"out of date location":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.
("This"指获取最后已知位置)。
此外,摘自 LocationProvider docs:
Each 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.
if the phone has GPS enabled, isn't this GPS tracking/updating as the phone moves?
是的,但不是一直如此。这与电池消耗有关,如果 phone 不断更新 GPS 位置,电池寿命会受到很大影响。 GPS 位置通常会在某些应用程序请求时更新。但即使是那个请求也不能保证成功。例如,假设您要进入隧道。某些应用程序请求在进入隧道之前更新 GPS 坐标并成功。现在,您已经进入了 5 公里长的隧道。您的设备很可能无法从隧道获得 GPS 定位,因此在接下来的 5 公里(至少)中,getLastKnownLocation()
将 return 一个过时的值, 因为设备最后已知的位置是在隧道的入口处。
您可以明确请求更新 GPS 位置,但这可能需要一些时间,而且无法保证一定会成功。
一些资源说 getLastKnownLocation()
仅仅给出了一些以前应用的位置变化监听器的位置。
但是我觉得谈话中遗漏了一件事——如果 phone 启用了 GPS,那么 phone 移动时这个 GPS tracking/updating 不是吗?所以如果我调用 getLastKnownLocation()
,它不是从 phone 不断更新的 GPS 获取当前 GPS 吗?
如果是这样,那么为什么人们警告不要使用它/指责它可能获得 "stale" 位置?如果 GPS 正在被跟踪/更新,并且 getLastKnownLocation()
一次性获取了它的当前位置,那么 getLastKnownLocation()
不好的原因是什么?
我对 Locations
服务或 GPS 有什么误解?
你有假设 "if the phone has GPS enabled, isn't this GPS tracking/updating as the phone moves"。这个假设是不正确的。 GPS 功能会占用大量电池寿命,因此应谨慎使用,而且几乎肯定不会一直使用。
documentation 说:Returns a Location indicating the data from the last known location fix obtained from the given provider.
另外,关于"out of date location":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.
("This"指获取最后已知位置)。
此外,摘自 LocationProvider docs:
Each 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.
if the phone has GPS enabled, isn't this GPS tracking/updating as the phone moves?
是的,但不是一直如此。这与电池消耗有关,如果 phone 不断更新 GPS 位置,电池寿命会受到很大影响。 GPS 位置通常会在某些应用程序请求时更新。但即使是那个请求也不能保证成功。例如,假设您要进入隧道。某些应用程序请求在进入隧道之前更新 GPS 坐标并成功。现在,您已经进入了 5 公里长的隧道。您的设备很可能无法从隧道获得 GPS 定位,因此在接下来的 5 公里(至少)中,getLastKnownLocation()
将 return 一个过时的值, 因为设备最后已知的位置是在隧道的入口处。
您可以明确请求更新 GPS 位置,但这可能需要一些时间,而且无法保证一定会成功。