我用这条线旋转标记
marker.setRotation((float) bearingBetweenLocations(startPosition, destination));
这会突然快速旋转。是他们减慢标记旋转速度的任何方法
答案 0 :(得分:0)
使用方式
float bearing = (float) bearingBetweenLocations(startPosition, new LatLng(destination.getLatitude(), destination.getLongitude()));
// mMarker.setRotation((float) bearingBetweenLocations();
rotateMarker(mMarker, bearing);
方法是
您可以在此处更改旋转标记功能final long duration = 500; // Change duration as you want
public double bearingBetweenLocations(LatLng latLng1, LatLng latLng2) {
double PI = 3.14159;
double lat1 = latLng1.latitude * PI / 180;
double long1 = latLng1.longitude * PI / 180;
double lat2 = latLng2.latitude * PI / 180;
double long2 = latLng2.longitude * PI / 180;
double dLon = (long2 - long1);
double y = Math.sin(dLon) * Math.cos(lat2);
double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
* Math.cos(lat2) * Math.cos(dLon);
double brng = Math.atan2(y, x);
brng = Math.toDegrees(brng);
brng = (brng + 360) % 360;
return brng;
}
public void rotateMarker(final Marker marker, final float toRotation) {
if (!isMarkerRotating) {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
final float startRotation = marker.getRotation();
final long duration = 500; // Change duration as you want
final Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
isMarkerRotating = true;
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed / duration);
float rot = t * toRotation + (1 - t) * startRotation;
float bearing = -rot > 180 ? rot / 2 : rot;
marker.setRotation(bearing);
if (t < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 4);
} else {
isMarkerRotating = false;
}
}
});
}
}
希望有帮助。