问题描述
- 应用程序中的location更新问题
- 在我的应用程序中,创建了一个 location manager,每十分钟来更新一次当前的location。
但结果是每5分钟更新一次。12-12 23:45:17.153: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m12-12 23:50:23.162: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m12-12 23:55:23.074: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m12-13 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_TAGLocation 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);
为什么不是每十分钟更新一次,而是五分钟更新一次呢?大家能帮忙解释一下这个问题吗?
解决方案
if(System.CurrentTimeMillis() > updateTime + currentTimeInMillis){ update your log here currentTimeInMillis = System.CurrentTimeMillis();}
时间: 2024-12-02 16:41:32