谷歌地图v2标记动画

GrI*_*sHu 8 android google-maps-api-3 google-maps-api-2 android-maps

有谁知道如何在谷歌地图api v2中实现这个动画的实现. 在这里看看. 我想知道这是怎么做到的.如果有人有任何关于此的示例代码,请告诉我.

提前致谢.

D-3*_*-32 9

我找到了一个适合我的解决方案:

final LatLng target = NEW_LOCATION;

final long duration = 400;
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 Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
    @Override
    public void run() {
        long elapsed = SystemClock.uptimeMillis() - start;
        if (elapsed > duration) {
            elapsed = duration;
        }
        float t = interpolator.getInterpolation((float) elapsed / duration);
        double lng = t * target.longitude + (1 - t) * startLatLng.longitude;
        double lat = t * target.latitude + (1 - t) * startLatLng.latitude;
        marker.setPosition(new LatLng(lat, lng));
        if (t < 1.0) {
            // Post again 10ms later.
            handler.postDelayed(this, 10);
        } else {
            // animation ended
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

  • 确保导入:import android.view.animation.Interpolator; import android.view.animation.LinearInterpolator; 而不是其他Interpolator. (2认同)

Com*_*are 7

欢迎您Marker通过电话随时更改a的位置setPosition().您可以通过CameraUpdate使用moveTo()animateTo()打开对象来随时更改"相机"的位置(即地图的中心和缩放级别)GoogleMap.将这些与光定时循环(例如,使用postDelayed())相结合应该可以实现类似的动画效果.