gpt4 book ai didi

android - 为什么我的应用程序位置更新速度是我指定的两倍?

转载 作者:行者123 更新时间:2023-11-29 15:30:17 25 4
gpt4 key购买 nike

在我的应用程序中,我设置了一个位置管理器来每 10 分钟更新一次当前位置(我是这么认为的)。相反,我每 5 分钟收到一次更新:

10-03 23:45:17.153: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m
10-03 23:50:23.162: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m
10-03 23:55:23.074: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m
10-04 00:00:23.077: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m

代码如下:

LocationManager locationManager = (LocationManager)
this.getSystemService(Context.LOCATION_SERVICE);

LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
Log.d(APP_TAG, "Location updated with accuracy: " + location.getAccuracy() + "m");
}
//Other methods are empty and omitted for brevity
};

int TEN_MINUTES = 10 /*Minutes*/ * 60 /*sec per min*/ * 1000 /*ms per sec*/;
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
TEN_MINUTES, 0, locationListener);

谁能解释为什么这不像我想的那样有效?例如。为什么它每 5 分钟而不是 10 分钟更新一次?

最佳答案

如 LocationManager.requestLocationUpdates() 文档中所述:

minTime: the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value.

因此,无法保证您不会更(或更不)频繁地获得更新。 GPS 芯片有可能能够提供更准确的位置信息,而无需消耗额外的电量,否则不允许要求的粒度级别。也有可能另一个应用程序也在后台请求更新。

更详细地回答可能需要了解手机中特定 GPS 接收器的工作原理。

关于android - 为什么我的应用程序位置更新速度是我指定的两倍?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7641686/

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