【问题标题】:Inertia for compass指南针的惯性
【发布时间】:2013-01-03 14:41:04
【问题描述】:

我正在使用 Google Maps API v2 开发一个应用程序。我已经构建了一个自定义位置源来为地图提供位置更新以及一些跟随用户的功能,所以 f.i.当用户按下“关注”按钮时,Aggiorna[=update]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。

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

@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等。这使得无法处理此功能。 谷歌地图如何使地图旋转如此顺畅且绝对稳定?他们实施了一种惯性,但如何? 有人想实现这样的功能吗?

【问题讨论】:

    标签: android location compass-geolocation


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2014-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多