Skip to content

Animation Types

This example showcases the different animation types.

  • Move: available via the MapMetricsMap.moveCamera method.
  • Ease: available via the MapMetricsMap.easeCamera method.
  • Animate: available via the MapMetricsMap.animateCamera method.

Move

The MapMetricsMap.moveCamera method jumps to the camera position provided.

kotlin
val cameraPosition =
    CameraPosition.Builder()
        .target(nextLatLng)
        .zoom(14.0)
        .tilt(30.0)
        .tilt(0.0)
        .build()
mapMetricsMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))

Ease

The MapMetricsMap.moveCamera eases to the camera position provided (with constant ground speed).

kotlin
val cameraPosition =
    CameraPosition.Builder()
        .target(nextLatLng)
        .zoom(15.0)
        .bearing(180.0)
        .tilt(30.0)
        .build()
mapMetricsMap.easeCamera(
    CameraUpdateFactory.newCameraPosition(cameraPosition),
    7500,
    callback
)

Animate

The MapMetricsMap.animateCamera uses a powered flight animation move to the camera position provided[^1].

[^1]: The implementation is based on Van Wijk, Jarke J.; Nuij, Wim A. A. “Smooth and efficient zooming and panning.” INFOVIS ’03. pp. 15–22. https://www.win.tue.nl/~vanwijk/zoompan.pdf#page=5

kotlin
val cameraPosition =
    CameraPosition.Builder().target(nextLatLng).bearing(270.0).tilt(20.0).build()
mapMetricsMap.animateCamera(
    CameraUpdateFactory.newCameraPosition(cameraPosition),
    7500,
    callback
)

Animation Callbacks

In the previous section a CancellableCallback was passed to the last two animation methods. This callback shows a toast message when the animation is cancelled or when it is finished.

kotlin
private val callback: CancelableCallback =
    object : CancelableCallback {
        override fun onCancel() {
            Timber.i("Duration onCancel Callback called.")
            Toast.makeText(
                applicationContext,
                "Ease onCancel Callback called.",
                Toast.LENGTH_LONG
            )
                .show()
        }

        override fun onFinish() {
            Timber.i("Duration onFinish Callback called.")
            Toast.makeText(
                applicationContext,
                "Ease onFinish Callback called.",
                Toast.LENGTH_LONG
            )
                .show()
        }
    }