设置在 Google 地图 Android 中更新位置的时间
Set time to update location in Google Map Android
我在我的应用程序中使用 Google 地图来及时更新位置。按照 Google 地图文档,我使用 setInterval(TIME_UPDATE) 设置更新位置的时间。这里的问题是我设置的时间和从 Google 地图响应位置更新的时间不一样。在我的代码中,我将时间设置为 1 秒( setInterval(1000) ),但是 Google 地图会在 5 秒后更新我的位置(我在室内)。当我在户外时,Google 地图会正确更新。这是我的代码:
private void makeLocationRequest(long secondUpdateLocation) {
REQUEST = LocationRequest.create().setInterval(1000) // set time to update
.setFastestInterval(1000) // set time to update
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, REQUEST,
this); // LocationListener
}
谁能帮帮我??非常感谢 :D
根据文档,该值不是 "Have to" 而只是一个不精确的值:
https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setInterval(long)
Set the desired interval for active location updates, in milliseconds.
The location client will actively try to obtain location updates for
your application at this interval, so it has a direct influence on the
amount of power used by your application. Choose your interval wisely.
This interval is inexact. You may not receive updates at all (if no
location sources are available), or you may receive them slower than
requested. You may also receive them faster than requested (if other
applications are requesting location at a faster interval). The
fastest rate that that you will receive updates can be controlled with
setFastestInterval(long). By default this fastest rate is 6x the
interval frequency.
Applications with only the coarse location permission may have their
interval silently throttled.
An interval of 0 is allowed, but not recommended, since location
updates may be extremely fast on future implementations.
因此无法保证更新会按您要求的速度进行,尤其是在室内,GPS 未完全正常工作,因此获取更新的速度可能较慢(在某些情况下,在室内您甚至无法获取更新).
我在我的应用程序中使用 Google 地图来及时更新位置。按照 Google 地图文档,我使用 setInterval(TIME_UPDATE) 设置更新位置的时间。这里的问题是我设置的时间和从 Google 地图响应位置更新的时间不一样。在我的代码中,我将时间设置为 1 秒( setInterval(1000) ),但是 Google 地图会在 5 秒后更新我的位置(我在室内)。当我在户外时,Google 地图会正确更新。这是我的代码:
private void makeLocationRequest(long secondUpdateLocation) {
REQUEST = LocationRequest.create().setInterval(1000) // set time to update
.setFastestInterval(1000) // set time to update
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, REQUEST,
this); // LocationListener
}
谁能帮帮我??非常感谢 :D
根据文档,该值不是 "Have to" 而只是一个不精确的值: https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setInterval(long)
Set the desired interval for active location updates, in milliseconds.
The location client will actively try to obtain location updates for your application at this interval, so it has a direct influence on the amount of power used by your application. Choose your interval wisely.
This interval is inexact. You may not receive updates at all (if no location sources are available), or you may receive them slower than requested. You may also receive them faster than requested (if other applications are requesting location at a faster interval). The fastest rate that that you will receive updates can be controlled with setFastestInterval(long). By default this fastest rate is 6x the interval frequency.
Applications with only the coarse location permission may have their interval silently throttled.
An interval of 0 is allowed, but not recommended, since location updates may be extremely fast on future implementations.
因此无法保证更新会按您要求的速度进行,尤其是在室内,GPS 未完全正常工作,因此获取更新的速度可能较慢(在某些情况下,在室内您甚至无法获取更新).