罗盘的惯性

时间:2013-01-20 10:08:45

标签: android location compass-geolocation inertia

我正在使用Google Maps API v2开发应用程序。我已经构建了一个自定义位置源来为Map提供位置更新,还有一些跟随用户的函数,所以f.i.当用户按下“跟随”按钮时,Aggiorna [=更新] BearingAuto和AggiornaPosAuto变为true:

@Override
public void OnBearingChanged(float bearing) {
    if (AggiornaBearingAuto)
    {
        mMap.moveCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder(mMap.getCameraPosition()).bearing(bearing).build()));
    }
}

@Override
public void OnLocationChanged(Location location) {
    if (AggiornaPosAuto)
    {
        CameraPosition Att = mMap.getCameraPosition();
        mMap.moveCamera(CameraUpdateFactory.newCameraPosition(
                CameraPosition.builder().bearing(Att.bearing).
                target(new LatLng(location.getLatitude(), location.getLongitude()))
                .tilt(Att.tilt).zoom(Att.zoom).build()
                ));
    }
}

并根据我班级提供的值更新CameraPosition。

现在,在该类中,提供Bearing更新的方法如下:

@Override
public void onSensorChanged( SensorEvent sensorEvent ) {

    float[] inR = new float[16];
    float[] I = new float[16];
    float[] orientVals = new float[3];

    double azimuth = 0;
    double pitch = 0;
    double roll = 0;
    // Gets the value of the sensor that has been changed
    switch (sensorEvent.sensor.getType()) {  
        case Sensor.TYPE_ACCELEROMETER:
            gravity = sensorEvent.values.clone();
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            geomag = sensorEvent.values.clone();
            break;
    }

    // If gravity and geomag have values then find rotation matrix
    if (gravity != null && geomag != null) {

        // checks that the rotation matrix is found
        boolean success = SensorManager.getRotationMatrix(inR, I, gravity, geomag);
        if (success) {
            SensorManager.getOrientation(inR, orientVals);
            azimuth = Math.toDegrees(orientVals[0]);
            pitch = Math.toDegrees(orientVals[1]);
            roll = Math.toDegrees(orientVals[2]);
        }
    }

        //finally, call OnBeraingChange in Listener
    LocListener.OnBearingChanged((float) azimuth);
}

确定。所以问题是:地图有时会很快地移动到足以令人讨厌,就像传感器连续提供-4,0,+ 4,0,+ 6,-5等一样。这使得无法处理此功能。 谷歌地图如何使地图旋转如此顺畅和绝对稳定?他们实现了一种惯性,但是如何? 有人有想法实现这样的功能吗?

2 个答案:

答案 0 :(得分:0)

我通过实施卡尔曼滤波器解决了这个问题。

答案 1 :(得分:0)

我有同样的问题,你必须实现低通过滤器,因为磁力计和加速度计的值更不稳定。 或者你必须实现一个更类似于低通滤波器的东西 看看这个:Android Compass orientation on unreliable (Low pass filter)