动态更改 GPS LocationListener 的 minTime

GPS*_*ter 0 gps android locationmanager

我正在编写的应用程序使用 GPS 位置管理器服务 requestLocationUpdates() 但我希望能够在整个程序中更改 min Time 和 min Distance 参数。我在创建时初始化了位置侦听器,但我不知道如何更改这些参数,甚至不知道是否可以这样做。这样做的主要目的是在程序不需要定期更新位置时节省电池寿命。非常感谢你的帮助!-Dom

小智 5

我不确定这是否正确,但面对同样的问题,我偶尔会删除 LocationListener,然后以不同的刷新间隔将其添加回来:

if (locationManager != null && locationListener != null) {
    locationManager.removeUpdates(locationListener);
}

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, refreshInterval, 50, locationListener);
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢!这很好用,我现在在我的应用程序中使用这种方法。对不起,我花了这么长时间才回复。在激动的时刻,我一定忘了感谢你。 (2认同)