即使设备不动,位置也会不断变化

Location keep changing even if the device is not moving

我正在使用 FusedLocationProviderClient 获取当前的经纬度,并且我正在使用以下代码获取设备的当前经纬度:

public class FusedGpsService extends Service {


private FusedLocationProviderClient fusedLocationProviderClient;
private double speed;
Data datas;
List<Location> locationList;


@Override
public void onCreate() {
    super.onCreate();

    fusedLocationProviderClient= LocationServices.getFusedLocationProviderClient(this);
    requestLocations();

    Log.i("STATR","Started");
}

@SuppressLint("MissingPermission")
private void requestLocations() {

    LocationRequest locationRequest=new LocationRequest();
    locationRequest.setInterval(1000);
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    fusedLocationProviderClient.requestLocationUpdates(locationRequest,locationCallback, Looper.myLooper());




}

LocationCallback locationCallback=new LocationCallback(){
    @Override
    public void onLocationResult(LocationResult locationResult) {
        super.onLocationResult(locationResult);

        datas=MainActivity.getData();




        locationList = locationResult.getLocations();

        if (locationList.size()>0){
            Location location =locationList.get(locationList.size() -1);

            double lat = location.getLatitude();
            double lon = location.getLongitude();

            Log.i("LATLONG", "Lat: "+String.valueOf(lat)+","+"Long: "+String.valueOf(lon));

            //speed = (double) ((location.getSpeed() * 3600)/1000);
            //datas.setCurrSpeed(speed);
            datas.update();

            //Log.i("SPIIID", String.valueOf(speed)+ "km/h");

        }
    }
};

@Override
public void onDestroy() {
    super.onDestroy();
    if (fusedLocationProviderClient!=null){
        fusedLocationProviderClient.removeLocationUpdates(locationCallback);


    }
}




@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}

}

一切似乎都很好,但如果我站着不动并且我没有移动,onLocationChanged() 方法仍然会被调用并不断将其更新为不同的 Lats 和 Longs。

有什么解决办法吗

FusedLocationProviderClient 未提供准确值,使用位置管理器并通过 location.getAccuracy() 检查位置的准确性并使用精度小于 20 的位置。