CameraPosition

  • CameraPosition is an immutable class that aggregates camera position parameters like location, zoom, tilt, and bearing.

  • You can use CameraPosition.Builder to create a CameraPosition instance.

  • CameraPosition can be used with CameraUpdateFactory to move the camera.

  • Key fields include bearing, target (location), tilt, and zoom.

public final classCameraPosition extendsObject
implementsParcelableParcelable

An immutable class that aggregates all camera position parameters such as location, zoom level, tilt angle, and bearing. UseCameraPosition.Builder to construct aCameraPosition instance, which you can then use in conjunction withCameraUpdateFactory. For more information, seeMoving the camera.

Developer Guide

For more information, read theCamera and View developer guide.

Nested Class Summary

classCameraPosition.BuilderBuilds camera position. 

Inherited Constant Summary

From interface android.os.Parcelable
intCONTENTS_FILE_DESCRIPTOR
intPARCELABLE_WRITE_RETURN_VALUE

Field Summary

public final floatbearingDirection that the camera is pointing in, in degrees clockwise from north.
public finalLatLngtargetThe location that the camera is pointing at.
public final floattiltThe angle, in degrees, of the camera angle from the nadir (directly facing the Earth).
public final floatzoomZoom level near the center of the screen.

Public Constructor Summary

CameraPosition(LatLng target, float zoom, float tilt, float bearing)
Constructs a CameraPosition.

Public Method Summary

staticCameraPosition.Builder
builder(CameraPosition camera)
Creates a builder for a camera position, initialized to a given position.
staticCameraPosition.Builder
builder()
Creates a builder for a camera position.
staticCameraPosition
createFromAttributes(Context context,AttributeSet attrs)
Creates a CameraPosition from theAttributeSet.
boolean
staticCameraPosition
fromLatLngZoom(LatLng target, float zoom)
Constructs a CameraPosition pointed for a particular target and zoom level.
int
String
void
writeToParcel(Parcel out, int flags)

Inherited Method Summary

From class java.lang.Object
Object
clone()
boolean
equals(Object arg0)
void
finalize()
finalClass<?>
getClass()
int
hashCode()
final void
notify()
final void
notifyAll()
String
toString()
final void
wait(long arg0, int arg1)
final void
wait(long arg0)
final void
wait()
From interface android.os.Parcelable
abstract int
describeContents()
abstract void
writeToParcel(Parcel arg0, int arg1)

Fields

public final floatbearing

Direction that the camera is pointing in, in degrees clockwise from north.

public finalLatLngtarget

The location that the camera is pointing at.

public final floattilt

The angle, in degrees, of the camera angle from the nadir (directly facing the Earth). See CameraPosition.Builder.tilt(float) for details of restrictions on the range of values.

public final floatzoom

Zoom level near the center of the screen. See CameraPosition.Builder.zoom(float) for the definition of the camera's zoom level.

Public Constructors

publicCameraPosition(LatLng target, float zoom, float tilt, float bearing)

Constructs a CameraPosition.

Parameters
targetThe target location to align with the center of the screen. Must not be null.
zoomZoom level at target. See CameraPosition.Builder.zoom(float) for details of restrictions.
tiltThe camera angle, in degrees, from the nadir (directly down). See CameraPosition.Builder.tilt(float) for details of restrictions.
bearingDirection that the camera is pointing in, in degrees clockwise from north. This value will be normalized to be within 0 degrees inclusive and 360 degrees exclusive.
Throws
NullPointerExceptioniftarget isnull
IllegalArgumentExceptioniftilt is outside the range of 0 to 90 degrees inclusive.

Public Methods

public staticCameraPosition.Builderbuilder(CameraPosition camera)

Creates a builder for a camera position, initialized to a given position.

public staticCameraPosition.Builderbuilder()

Creates a builder for a camera position.

public staticCameraPositioncreateFromAttributes(Context context,AttributeSet attrs)

Creates a CameraPosition from theAttributeSet.

Returns
  • null if eithercontext orattrs is null.

public booleanequals(Object o)

public staticCameraPositionfromLatLngZoom(LatLng target, float zoom)

Constructs a CameraPosition pointed for a particular target and zoom level. The resultant bearing is North, and the viewing angle is perpendicular to the Earth's surface. i.e., directly facing the Earth's surface, with the top of the screen pointing North.

Parameters
targetThe target location to align with the center of the screen.
zoomZoom level at target. See CameraPosition.Builder.zoom(float) for details on the range the value will be clamped to. The larger the value the more zoomed in the camera is.

public inthashCode()

publicStringtoString()

public voidwriteToParcel(Parcel out, int flags)

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-10-31 UTC.