getLastLocation() 是否请求当前位置?

Is getLastLocation() make a request for the current location?

我正在使用 google api 融合位置。我想在不使用 LocationListener 接口连续跟踪位置的情况下高精度地获取当前位置。

我有一个简单的用例:用户点击按钮,应用程序将显示当前的纬度和经度(新位置)。

那么,getLastLocation() 是从缓存中检索位置(这意味着它在某些情况下可能不准确)还是发出位置请求以获取新数据?

如果不是,是否可以在不实现 LocationListener 接口的情况下实现我的用例?

根据 the andoid website 上的文档。

To request the last known location, call the getLastLocation() method, passing it your instance of the GoogleApiClient object. Do this in the onConnected() callback provided by Google API Client, which is called when the client is ready. The following code snippet illustrates the request and a simple handling of the response:

这意味着它不会在您调用 getLastLocation() 时更新位置。这将在基于更新的服务上完成。

您可以使用此功能请求位置更新

protected void startLocationUpdates() {
    LocationServices.FusedLocationApi.requestLocationUpdates(
    mGoogleApiClient, mLocationRequest, this);
}