我正在開發一個帶有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地圖如何使地圖旋轉如此平穩並且絕對穩定?他們實施了一種慣性,但怎麼樣? 有人有想法來實現這樣的功能嗎?