我正在使用 Google Maps API v2 开发应用程序。我已经构建了一个自定义位置源来为地图提供位置更新以及一些跟随用户的功能,所以当用户按下“关注”按钮时,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等。这使得无法处理此功能。谷歌地图如何让地图旋转如此顺畅且绝对稳定?他们实施了一种惯性,但如何?有人想实现这样的功能吗?