我正在使用 FusedLocationApi 获取更新。但是尽管将 LocationRequest.setInterval 设置为 500 甚至 200 毫秒,但我每秒只能获得一次更新。如果可能的话,我想每秒两次(做一个移动平均速度)。有硬性限制吗?
在我的 Activity onCreate 中:
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(AppIndex.API).build();
在我的“onConnected”方法中:
this.locationRequest = new LocationRequest();
this.locationRequest.setInterval(200);
this.locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(this.googleApiClient, this.locationRequest, this);
我还有一个单独的 LocationManager,我只使用它来通过 addGpsStatusListener() 获取状态更改,这些似乎工作正常。
谢谢
最佳答案
根据文档
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.
您可以尝试使用public LocationRequest setFastestInterval (long millis)
。文档指出:
he fastest rate that that you will receive updates can be controlled with setFastestInterval(long). By default this fastest rate is 6x the interval frequency.
同时确保您请求 ACCESS_FINE_LOCATION
。该文档还指出:
Applications with only the coarse location permission may have their interval silently throttled
关于Android onLocationChanged 最快每秒只调用一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38083372/