我想創建一個應用程序,如奧拉/超級。我想要移動圖標並在路左轉或右轉時旋轉。我正在使用以下代碼。谷歌地圖旋轉標記/汽車圖標 - Android
private 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 = 1000;
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;
marker.setRotation(-rot > 180 ? rot/2 : rot);
if (t < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
} else {
isMarkerRotating = false;
}
}
});
}
}
爲了計算軸承:
currentLocation = location;
if(previousLocaton!=null){
previousLocaton = tempLocation;
tempLocation = currentLocation;
Log.d("previousLocaton=====> ",""+previousLocaton);
Log.d("currentLocation=====> ",""+currentLocation);
bearing = previousLocaton.bearingTo(currentLocation) ;
}else{
previousLocaton = location;
tempLocation = location;
}
要設置軸承:
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng).zoom(14).bearing(bearing).build();
要旋轉標記我請roateMarker方法在onLocationChanged
改變的方法:
currLocationMarker = mMap.addMarker(markerOptions);
rotateMarker(currLocationMarker,bearing);
現在我的圖標正在旋轉。但谷歌地圖也旋轉。我想單獨旋轉圖標。我將以下鏈接指向動畫並移動標記。 Link 1。請讓我有任何想法來解決我的問題。
我會嘗試這一點,讓你很快就知道.. – Vijay
您好..對不起,長時間的休息..這也工作得很好。但我面臨另一個問題。我每5秒更換一次標記。當我更換標記時,標記位置從它的真實位置開始。對於我的標記是箭頭標記默認它表示頂級天使。當我從一個地方移動到另一個地方時,我的標記旋轉,並突然從頂部天使開始。請讓我有任何想法來解決這個問題。 – Vijay
這是一個簡單的解決方案,工作正常..! – Vijay