gpt4 book ai didi

android - 在 Google Map Android 中设置更新位置的时间

转载 作者:行者123 更新时间:2023-11-30 01:57:01 24 4
gpt4 key购买 nike

我在我的应用程序中使用谷歌地图来及时更新位置。按照谷歌地图文档,我使用 setInterval(TIME_UPDATE) 来设置更新位置的时间。这里的问题是我设置的时间和从谷歌地图响应位置更新的时间不一样。在我的代码中,我将时间设置为 1 秒( setInterval(1000) ),但 Google map 会在 5 秒后更新我的位置(我在室内)。当我在户外时,谷歌地图会正确更新。这是我的代码:

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

最佳答案

根据文档,该值不是“必须”,而只是一个不精确的值: 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 未完全正常工作,因此获取更新的速度可能较慢(在某些情况下,在室内您甚至无法获取更新)。

关于android - 在 Google Map Android 中设置更新位置的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32067356/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com