我已经在我的 Activity 中实现了 OnLocationChanged(Location location) 作为覆盖方法,如下所示:
@Override
public void onLocationChanged(Location location) {
mCurrentLocation = location;
if (wifiSpotList != null) {
presenter.onLocationUpdated(wifiSpotList, mCurrentLocation);
centerInLoc(location);
}
}
问题是,即使设备没有移动,这个方法也会被触发。它总是以毫秒为间隔发生。
调试器通过位置参数获取此日志:
mTime = 1446035851646
mLongitude = -3.6923793
mLatitude = 40.5008861
mTime = 1446035856976
mLongitude = -3.6923596
mLatitude = 40.5008932
mTime = 1446035867327
mLongitude = -3.6923681
mLatitude = 40.5008987
mTime = 1446035877344
mLongitude = -3.6923778
mLatitude = 40.5008949
mTime = 1446035882442
mLongitude = -3.6923734
mLatitude = 40.5008926
...
编辑:
这是初始化 requestLocationUpdates 的代码:
protected void startLocationUpdates() {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
this.locationUpdatesStarted = true;
}
编辑 mLocationRequest:
protected void createLocationRequest() {
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(LOCATION_REQUEST_INTERVAL);
mLocationRequest.setFastestInterval(LOCATION_REQUEST_FASTEST_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
this.mLocationRequest = mLocationRequest;
}
方法是因为经\纬度变化而触发的吗? 为什么即使设备没有移动它也会触发? 我可以限制准确性吗? 有什么干净的方法来实现 onLocationChanged() 吗?
最佳答案
setSmallestDisplacement(float smallestDisplacementMeters)
您必须以米为单位设置位置更新之间的最小位移 默认为 0。
关于android - onLocationChanged() 被调用太多次,即使设备没有移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33391401/