gpt4 book ai didi

android - onLocationChanged() 被调用太多次,即使设备没有移动

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:16:48 24 4
gpt4 key购买 nike

我已经在我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com