Skip to main content

The camera

Contents

The camera is how the user views the map. It can be centered on a location, zoomed, tilted, rotated and moved. The camera can be set programmatically but also controlled through user interaction with gestures.

The camera is typically set using the CameraPosition class which is made up of target, zoom, bearing and tilt parameters.

Attribute Type Description Default Setting
Target
LatLng object
Where the camera should center on the map. Required
Zoom
double
The zoom level of the camera; ranges from 0 to 22. 0
Bearing
double
The rotation of the camera in degrees clockwise from north. 0 (true north)
Tilt
double
The camera’s angle when viewing the map. Ranges from 0 to 60. 0 (bird’s eye view)

Setting the CameraPosition

There are many ways to set the camera position on the map, but the most common method is to use the CameraPosition’s Builder. This example code snippet has to be added inside the onStyleLoaded() method for Java and inside the setStyle() method for Kotlin

The above code sets the camera’s target/center to be a coordinate in New York City and sets the zoom level to 13. Once the CameraPosition is built, the map is updated with the new position.

Animating the CameraPosition

In addition to setting the map’s camera position, you can also animate a “flight” to a new camera position, “gliding” into the new position in a straight line from the current position. The map’s animateCamera() method allows for this using a CameraUpdate object as a parameter. An example of this is below:

Similar to the previous example, the CameraPosition is created, CameraUpdateFactory can then use this position to generate the CameraUpdate object animateCamera() requires. The second parameter is an optional duration for the animation in milliseconds.

Besides animateCamera(), the SDK provides the methods moveCamera(), which instantly moves the camera to the specified position without any animation, and easeCamera(), which smoothly animates the camera to the specified position with a decelerating effect.

Framing the view to a set of locations

The camera functions can be used to adjust the view to the bounds of a set of locations, such as coordinates, addresses, or places. These functions help in ensuring that all specified points are visible within the map’s viewport.

You can use the CameraUtils.frameLocationOrPolygon() method to generate a CameraUpdate object that contains the necessary camera position to fit the specified points within the view, and then pass this CameraUpdate object to any of the camera functions.

Last updated January 15, 2025.
Contents