我想通过MapView
更改后的价值来轮播sensor
。但它并不像Google Maps
申请那么顺利。似乎连续调用的animate
方法导致maps
轴承不平滑。似乎新animateCamera
来电会取消之前的animation
来电,不是吗?我在下面的代码中做错了什么?我可以提高轴承性能吗?
mSensorManager.setOnDeviceRotationListener(bearing -> {
if (mCurrentLocation == null
|| Math.abs(mOldBearing - bearing) < ROTATION_THRESHOLD) { // atleast 5 degrees.
return;
}
mOldBearing = bearing;
LatLng target =
new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
CameraPosition oldCamera = mGoogleMap.getCameraPosition();
CameraPosition newCamera = CameraPosition.builder()
.zoom(Math.max(oldCamera.zoom, DEFAULT_MAP_COMPASS_ZOOM))
.target(target)
.tilt(DEFAULT_MAP_TILT)
.bearing(bearing)
.build();
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(newCamera));
}