Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 谷歌地图安卓上添加动画的标记摇摆不定_Android_Google Maps_Android Animation_Marker - Fatal编程技术网

Android 谷歌地图安卓上添加动画的标记摇摆不定

Android 谷歌地图安卓上添加动画的标记摇摆不定,android,google-maps,android-animation,marker,Android,Google Maps,Android Animation,Marker,我使用这段代码来设置标记的动画,类似于在google地图上复制车辆的移动,但是当在处理程序函数中调用marker.setPosition时,标记会剧烈晃动。代码如下: public static void animateMarker(final GoogleMap map, final Marker marker, final LatLng toPosition) { final Handler handler = new Handler(); final long start

我使用这段代码来设置标记的动画,类似于在google地图上复制车辆的移动,但是当在处理程序函数中调用marker.setPosition时,标记会剧烈晃动。代码如下:

public static void animateMarker(final GoogleMap map, final Marker marker, final LatLng toPosition) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = map.getProjection();
    Point startPoint = proj.toScreenLocation(marker.getPosition());
    final LatLng startLatLng = proj.fromScreenLocation(startPoint);
    final long duration = 5000;
    final Interpolator interpolator = new LinearInterpolator();
    handler.post(new Runnable() {
        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude;
            double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude;
            marker.setPosition(new LatLng(lat, lng));
            if (t < 1.0) {
                handler.postDelayed(this, 16);
            }
        }
    });
}
public static void animateMarker(最终谷歌地图、最终标记、最终LatLng地形){
最终处理程序=新处理程序();
最终长启动=SystemClock.uptimeMillis();
Projection proj=map.getProjection();
Point startPoint=proj.toScreenLocation(marker.getPosition());
最终LatLng StartAtlng=屏幕位置(起始点)的项目;
最终长持续时间=5000;
最终插值器插值器=新的线性插值器();
handler.post(新的Runnable(){
@凌驾
公开募捐{
长时间运行=SystemClock.uptimeMillis()-开始;
float t=interpolator.getInterpolation((float)经过时间/持续时间);
双lng=t*地形经度+(1-t)*地形经度;
双纬度=t*地形纬度+(1-t)*纬度;
标记器设置位置(新板条(板条,板条));
如果(t<1.0){
handler.postDelayed(这是16);
}
}
});
}
尝试使用,这是一种变化率开始和结束缓慢但从中间加速的插值器,而不是本文中使用的线性插值器。标记动画是无缝的。以下是片段:

public class MarkerAnimation {
    static void animateMarkerToGB(final Marker marker, final LatLng finalPosition, final LatLngInterpolator latLngInterpolator) {
        final LatLng startPosition = marker.getPosition();
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final Interpolator interpolator = new AccelerateDecelerateInterpolator();
        final float durationInMs = 3000;

    handler.post(new Runnable() {
        long elapsed;
        float t;
        float v;

        @Override
        public void run() {
            // Calculate progress using interpolator
            elapsed = SystemClock.uptimeMillis() - start;
            t = elapsed / durationInMs;
            v = interpolator.getInterpolation(t);

            marker.setPosition(latLngInterpolator.interpolate(v, startPosition, finalPosition));

            // Repeat till progress is complete.
            if (t < 1) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            }
        }
    });
}

Full code [here](https://gist.github.com/broady/6314689).
公共类标记动画{
静态无效动画标记GB(最终标记标记、最终LatLng最终位置、最终LatLngInterpolator LatLngInterpolator){
最终车床开始位置=marker.getPosition();
最终处理程序=新处理程序();
最终长启动=SystemClock.uptimeMillis();
最终插值器插值器=新的加速加速插值器();
最终浮动持续时间Nms=3000;
handler.post(新的Runnable(){
久违;
浮动t;
浮动v;
@凌驾
公开募捐{
//使用插值器计算进度
已用=SystemClock.uptimeMillis()-开始;
t=经过时间/持续时间Nms;
v=插值器。getInterpolation(t);
marker.setPosition(LatlInInterPolator.interpolate(v,起始位置,最终位置));
//重复,直到进度完成。
if(t<1){
//16毫秒后再次发布。
handler.postDelayed(这是16);
}
}
});
}
完整代码[此处](https://gist.github.com/broady/6314689).

您能解决这个问题吗?