2013-01-20 174 views
0

我正在开发一个带有Google Maps API v2的应用程序。我已经构建了一个自定义位置源来为位图提供位置更新,还有一些功能可以跟随用户,所以f.i.当用户按下“跟随”按钮Aggiorna [=更新] BearingAuto和AggiornaPosAuto成为真:指南针惯性

@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等一样。这使得不可能处理这个功能。 Google地图如何使地图旋转如此平稳并且绝对稳定?他们实施了一种惯性,但怎么样? 有人有想法来实现这样的功能吗?

回答

0

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