Google Map v2标记出现时添加动画

时间:2018-03-08 17:06:54

标签: android android-animation google-maps-markers google-maps-android-api-2

在iOS中,Google地图允许在地图上标记弹出时提供动画。

我希望在Android上做同样的事情。所以没有什么可做的,或者有人知道解决方法?

2 个答案:

答案 0 :(得分:0)

您可以使用常规Android方法为标记设置动画:Animations and Transitions。以thisthat为例:

private static void animateMarker(final Marker marker, final int current, final LatLng[] line) {
    if (line == null || line.length == 0 || current >= line.length) {
        return;
    }

    ObjectAnimator animator = ObjectAnimator.ofObject(marker, property, typeEvaluator, line[current]);
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            animateMarker(marker, current + 1, line);
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });

    animator.setDuration(DURATION);
    animator.start();
}

或使用库,例如​​that

答案 1 :(得分:0)

根据服务器上的response,您会收到/摘录latitudelongitude

 //call this method for adding marker with lat and long

    public void addmarker(){
     LatLng marker = new LatLng(double lat, double long);
            googleMap.addMarker(new MarkerOptions().position(marker)
                    .title("My title"));
            googleMap.moveCamera(CameraUpdateFactory.newLatLng(marker));
// now the marker is set
// add a delay of 100-200 ms and start you animation (delay for failsafe)
    }