Vij*_*jay 5 android google-maps rotation
我正在尝试创建一个像 ola/uber 这样的应用程序。我想在道路左转或右转时移动图标并旋转。我正在使用以下代码。
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;
}
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
计算轴承:
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;
}
Run Code Online (Sandbox Code Playgroud)
要设置轴承:
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng).zoom(14).bearing(bearing).build();
Run Code Online (Sandbox Code Playgroud)
要旋转标记,我在onLocationChanged更改的方法中调用 roateMarker方法:
currLocationMarker = mMap.addMarker(markerOptions);
rotateMarker(currLocationMarker,bearing);
Run Code Online (Sandbox Code Playgroud)
现在我的图标在旋转。但谷歌地图也会旋转。我想单独旋转图标。我参考以下链接进行动画和移动标记。链接 1。请让我有任何想法来解决我的问题。
有一种简单的方法可用于标记
marker.rotation(float value)
Run Code Online (Sandbox Code Playgroud)
设置标记围绕标记的锚点顺时针旋转的度数。旋转轴垂直于标记。旋转 0 对应于标记的默认位置。当标记在地图上是平坦的时,默认位置是北对齐,并且旋转使得标记在地图上始终保持平坦。当标记是广告牌时,默认位置是向上的并且旋转使得标记始终面向相机。默认值为 0。
| 归档时间: |
|
| 查看次数: |
6741 次 |
| 最近记录: |