简体   繁体   English

Android Google Maps通过动画将相机移动到不同位置

[英]android google maps moving the camera to different locations with animation

Hi I am trying to change the camera in different locations with an animation. 嗨,我正在尝试用动画在不同位置更改相机。 What happens is that when the map opens it zooms to a location then it stops for 6 secs and then it moves to another location with a camera animation. 发生的事情是,当地图打开时,它将缩放到一个位置,然后停止6秒钟,然后使用照相机动画将其移动到另一个位置。 My question is that when this is finished how can I create a 3rd location and then move the camera from the 2nd location to the 3rd? 我的问题是,完成此操作后如何创建第3个位置,然后将相机从第2个位置移动到第3个位置? Any idea guys ? 有想法吗? Thanks. 谢谢。 Here is my code. 这是我的代码。

   public class THEMAP extends Activity {

   @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    GoogleMap map = ((MapFragment) getFragmentManager()
            .findFragmentById(R.id.map)).getMap();

    LatLng loc1 = new LatLng(41.889, -87.622);
    LatLng loc2 = new LatLng(45.889, -87.622);
    LatLng loc3 = new LatLng(49.889, -87.622);



    map.moveCamera(CameraUpdateFactory.newLatLngZoom(loc1, 10));

    map.animateCamera(CameraUpdateFactory.zoomIn());
    map.animateCamera(CameraUpdateFactory.zoomTo(10), 6000, null);

    map.addMarker(new MarkerOptions()
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.green))
            .position(loc2)
            .flat(true)
            .rotation(245));

    map.addMarker(new MarkerOptions()
    .icon(BitmapDescriptorFactory.fromResource(R.drawable.green))
    .position(loc1)
    .flat(true)
    .rotation(245));

    map.addMarker(new MarkerOptions()
    .icon(BitmapDescriptorFactory.fromResource(R.drawable.green))
    .position(loc3)
    .flat(true)
    .rotation(245));


    CameraPosition cameraPosition = new CameraPosition.Builder()
    .target(mapCenter2)     
    .zoom(8)                   
    .bearing(90)                
    .tilt(30)                   
    .build();                   



  map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition ),
    8000, null);

   }

  }

The problem is that if i add another location+marker and try to do the above code, the map animates only the 3rd location ignoring the animation of the 2nd location. 问题是,如果我添加另一个位置+标记并尝试执行上面的代码,则地图将仅对第三位置设置动画,而忽略第二位置的动画。 Any advice guys ?Please help. 有什么建议吗?请帮忙。

    CameraPosition cameraPosition2 = new CameraPosition.Builder()
    .target(loc3)     
    .zoom(8)                  
    .bearing(90)               
    .tilt(30)                   
    .build();                   



   map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition2 ),
    8000, null);

Here's your answer: http://ddewaele.github.io/GoogleMapsV2WithActionBarSherlock/part3 这是您的答案: http : //ddewaele.github.io/GoogleMapsV2WithActionBarSherlock/part3

It seems you need to implement the second animation in the onFinish() callback of the second animation. 似乎您需要在第二个动画的onFinish()回调中实现第二个动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM