简体   繁体   English

定位服务的`getLastKnownLocation()`是否检查手机的当前GPS位置?

[英]Does Location Services' `getLastKnownLocation()` check phone's current GPS location?

Some resources say getLastKnownLocation() merely gives a location of some previous app's Location Change Listener. 一些资源说getLastKnownLocation()仅给出了某个先前应用的位置更改监听器的位置。

But one thing I feel is missing from the conversation -- if the phone has GPS enabled, isn't this GPS tracking/updating as the phone moves? 但是对话中我缺少一件事-如果手机启用了GPS,随着手机移动,这不是GPS跟踪/更新吗? So if I call getLastKnownLocation() , isn't it getting the current GPS from the phone's constantly-updated GPS? 因此,如果我调用getLastKnownLocation() ,是不是从手机不断更新的GPS获取当前的GPS?

If so, then why do people warn against using it / accuse it of potentially getting a "stale" location? 如果是这样,那为什么人们要警告不要使用它/指责它可能获得“陈旧”的位置? If the GPS is being tracked / updated, and getLastKnownLocation() makes a one-time grab of it's current position, what makes getLastKnownLocation() bad? 如果正在跟踪/更新GPS,并且getLastKnownLocation()一次性获取了它的当前位置,是什么使getLastKnownLocation()变坏了?

What am I mistaken about the Locations service or GPS? 我对Locations服务或GPS有什么误解?

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

Also, about the "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 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 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" refers to getting the last known location). (“此”是指获得最后一个已知位置)。

Also, taken from 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. 另外,摘自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. 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? 如果手机启用了GPS,那么手机移动时GPS不会跟踪/更新吗?

Well, it is, but not constantly. 是的,但是不是一直。 This has to do with battery consumption, if the phone was constantly updating the GPS location, the battery life would suffer a lot. 这与电池消耗有关,如果手机不断更新GPS位置,电池寿命将受到很大影响。 The GPS location is usually updated when some app requests it. GPS位置通常在某些应用程序请求时进行更新。 But even that request is not guaranteed to succeed. 但是,即使该请求也不能保证成功。 For example, suppose your going into a tunnel. 例如,假设您要进入隧道。 Some application requests to update the GPS coordinates right before entering the tunnel and it succeeds. 某些应用程序要求在进入隧道之前立即更新GPS坐标,然后它会成功。 Now, you've entered the tunnel, which is 5km long. 现在,您已经进入了5公里长的隧道。 Most probably your device won't be able to get a GPS fix from the tunnel, so for the next 5km (at least) getLastKnownLocation() will return an outdated value, since the devices last known location was at the entrance of the tunnel . 您的设备很可能无法从隧道中获取GPS定位,因此在接下来的5公里(至少)内, getLastKnownLocation()将返回过时的值, 因为设备的最后一个已知位置位于隧道的入口

What you could do is explicitly request to update the GPS location, that however might take some time and there are no guarantees that it will succeed. 您可以做的是明确请求更新GPS位置,但是这可能需要一些时间,并且不能保证会成功。

You have the assumption "if the phone has GPS enabled, isn't this GPS tracking/updating as the phone moves". 您假设“如果手机启用了GPS,那么手机移动时GPS不会跟踪/更新”。 This assumption is incorrect. 这个假设是不正确的。 The GPS functionality takes up a lot of battery life so it should be used sparingly and almost certainly not all the time. GPS功能会占用大量电池电量,因此应谨慎使用,并且几乎可以肯定并非所有时间都可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM