当它被添加到Android上映射如何动画标记?当它、标记、动画、Android

2023-09-05 08:51:12 作者:烛半

我想,当他们被添加到地图动画地图标记。

用户应该看到身边的标记在地图上。每一个新的标志应该反弹。

解决方案

您可以执行 onMarkerClick()并做出标记,只要反弹用户点击就可以了。 刚刚尝试跌破code实现。我已经尝试过了,它工作完全正常。

 专用标记mPerth;
 私人标记mPerth = mMap.addMarker(新MarkerOptions()
             .position(PERTH)
            .title伪(珀斯)
            是.snippet(人口:1738800));
 
21 款炫酷动画开源框架,照亮你的APP

  @覆盖
公共布尔onMarkerClick(最终标记标记)
  {
      //这使得标记在珀斯反弹到位被点击时。
    如果(marker.equals(mPerth)){
        最终的处理程序处理程序=新的处理程序();
        最终长开始= SystemClock.uptimeMillis();
        投影PROJ = mMap.getProjection();
        点的startPoint = proj.toScreenLocation(PERTH);
        startPoint.offset(0,-100);
        最后的经纬度startLatLng = proj.fromScreenLocation(的startPoint);
        最后,持续时间长= 1500;
        最终插补插补器=新BounceInterpolator();
        handler.post(新的Runnable(){
            @覆盖
            公共无效的run(){
                经过长= SystemClock.uptimeMillis() - 启动;
                浮动T = interpolator.getInterpolation((浮点)经过/时间);
                双LNG = T * PERTH.longitude +(1  -  T)* startLatLng.longitude;
                双纬度= T * PERTH.latitude +(1  -  T)* startLatLng.latitude;
                marker.setPosition(新经纬度(纬度,经度));
                如果(T< 1.0){
                    //邮稍后再为16ms。
                    handler.postDelayed(这一点,16);
                }
            }
        });
    }
    //我们返回false,表明我们还没有消耗的事件,我们希望
    //对于发生的默认行为(即,相机移动,使得
    //标志为中心,并为标记的信息窗口打开,如果有的话)。
    返回false;
}
 

您也可以使用这个在添加应用程序中的标记之外的onClick 事件的时间。 我希望这只是你想要的东西。

I want to animate map markers when they are added to map.

User should see the map with markers around him. Each new marker should bounce.

解决方案

You can implement the onMarkerClick() and make the marker bounce whenever user clicks on it. Just try out below code implementation. I have tried it and it works totally fine.

 private Marker mPerth;  
 private Marker mPerth = mMap.addMarker(new MarkerOptions()
             .position(PERTH)
            .title("Perth")
            .snippet("Population: 1,738,800"));        

  @Override   
public boolean onMarkerClick(final Marker marker) 
  {
      // This causes the marker at Perth to bounce into position when it is clicked.
    if (marker.equals(mPerth)) {
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        Projection proj = mMap.getProjection();
        Point startPoint = proj.toScreenLocation(PERTH);
        startPoint.offset(0, -100);
        final LatLng startLatLng = proj.fromScreenLocation(startPoint);
        final long duration = 1500;
        final Interpolator interpolator = new BounceInterpolator();
        handler.post(new Runnable() {
            @Override
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = interpolator.getInterpolation((float) elapsed / duration);
                double lng = t * PERTH.longitude + (1 - t) * startLatLng.longitude;
                double lat = t * PERTH.latitude + (1 - t) * startLatLng.latitude;
                marker.setPosition(new LatLng(lat, lng));
                if (t < 1.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    }
    // We return false to indicate that we have not consumed the event and that we wish
    // for the default behavior to occur (which is for the camera to move such that the
    // marker is centered and for the marker's info window to open, if it has one).
    return false;
}

You can also use this at the time of adding the marker in your application besides onClick event. I hope this what you want only.