So, finally found my own answer, which I will post here so that others may find it useful.
, onLocationChanged, , . .
double oldLat = oldLocation.getLatitude();
double oldLng = oldLocation.getLongitude();
double newLat = newLocation.getLatitude();
double newLng = newLocation.getLongitude();
if (oldLat != newLat && oldLng != newLng){
updateMyLocation(toLatLng(oldLocation), toLatLng(mCurrentLocation));
}
. . ( ).
float rotation = (float) SphericalUtil.computeHeading(old, new);
rotateMarker(bus_marker, new, rotation);
private void rotateMarker(final Marker marker, final LatLng destination, final float rotation) {
if (marker != null) {
final LatLng startPosition = marker.getPosition();
final float startRotation = marker.getRotation();
final LatLngInterpolator latLngInterpolator = new LatLngInterpolator.Spherical();
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
valueAnimator.setDuration(3000);
valueAnimator.setInterpolator(new LinearInterpolator());
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
try {
float v = animation.getAnimatedFraction();
LatLng newPosition = latLngInterpolator.interpolate(v, startPosition, destination);
float bearing = computeRotation(v, startRotation, rotation);
marker.setRotation(bearing);
marker.setPosition(newPosition);
}
catch (Exception e){
e.printStackTrace();
}
}
});
valueAnimator.start();
}
}
private static float computeRotation(float fraction, float start, float end) {
float normalizeEnd = end - start;
float normalizedEndAbs = (normalizeEnd + 360) % 360;
float direction = (normalizedEndAbs > 180) ? -1 : 1;
float rotation;
if (direction > 0) {
rotation = normalizedEndAbs;
} else {
rotation = normalizedEndAbs - 360;
}
float result = fraction * rotation + start;
return (result + 360) % 360;
}