android camera position, google maps

2019-09-01 01:28发布

问题:

Hi I have the above code which animates the camera to a certain location. Is there anyway that I could move the camera position to a different position once it has finished the animation from the first location ? I am trying an if statement but it doesn't work.

for instance:

    CameraPosition cameraPosition = new CameraPosition.Builder()
    .target(1stlocation)     
    .zoom(12)                   
    .bearing(300)                
    .tilt(30)                   
    .build();     


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


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

//if statement to change the position of the camera when it reaches the first location then move it to another.

  CameraPosition campos = map.getCameraPosition();

  if(campos == cameraPosition )
  {

      map.moveCamera(CameraUpdateFactory.newLatLngZoom(2ndloc, 3));
  }

回答1:

Register for a call back onFinish, then just call your next animation. You could chain them with a simple counter.

map.animateCamera(CameraUpdateFactory.newLatLng(cameraPositiom), new CancelableCallback(){

    @Override
    public void onFinish(){
        googleMap.getUiSettings().setScrollGesturesEnabled(true);
    }

    @Override
    public void onCancel(){
        googleMap.getUiSettings().setAllGesturesEnabled(true);

    }
});