Android onLocationChanged 最快每秒调用一次
Android onLocationChanged only called once a second at fastest
我正在使用 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
正如 "LocationRequest.setInterval()" 文档所说
The location client will actively try to obtain location updates for your application at this interval[...]
因此您可能无法以所需的频率更新位置。这是因为位置检索技术(GPS、WiFi 等)的性质非常依赖硬件(以及 Google 的融合位置提供程序算法),还取决于大气条件(在 GPS 中案件)。如果要获得高精度的位置,那么设备需要先获取一些样本,才能进行高精度的估计。
我正在使用 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
正如 "LocationRequest.setInterval()" 文档所说
The location client will actively try to obtain location updates for your application at this interval[...]
因此您可能无法以所需的频率更新位置。这是因为位置检索技术(GPS、WiFi 等)的性质非常依赖硬件(以及 Google 的融合位置提供程序算法),还取决于大气条件(在 GPS 中案件)。如果要获得高精度的位置,那么设备需要先获取一些样本,才能进行高精度的估计。