Skip to content

KrossCameraPositionState

Farman Ullah Khan edited this page Jul 30, 2025 · 1 revision

🗺️ KrossCameraPositionState Component Documentation

A cross-platform camera state controller for map views in Kotlin Multiplatform apps.


🔹 Overview

Element Type Description
KrossCameraPositionState Expect Class Maintains camera position and provides animation controls.
rememberKrossCameraPositionState Composable Creates and retains the camera state within a Compose environment.

🧭 KrossCameraPositionState

Definition:
An expect class that defines the current camera state and provides utilities to animate camera movements on a map.

Properties

Property Type Description
tilt Float The tilt angle of the camera (0 = top-down, higher = angled view).
cameraFollow Boolean If true, the camera automatically follows the target (e.g., user or marker).

🌀 animateCamera(...)

Animates the map camera to a new position with optional controls.

Parameter Type Default Description
latitude Double? null Target latitude. If null, latitude remains unchanged.
longitude Double? null Target longitude. If null, longitude remains unchanged.
bearing Float? null New direction the camera should face.
tilt Float? null Desired tilt of the camera.
zoom Float? null Desired zoom level.
durationMillis Int 1000 Duration of the animation in milliseconds.

🧠 rememberKrossCameraPositionState

Creates and retains a KrossCameraPositionState tied to the Compose lifecycle.

Parameters

Parameter Type Default Description
latitude Double — Initial latitude of the camera.
longitude Double — Initial longitude of the camera.
zoom Float 0f Initial zoom level.
tilt Float 0f Initial camera tilt in degrees.
bearing Float 0f Initial direction the camera should face.
cameraFollow Boolean true Whether the camera should follow movement automatically.

✅ Usage Example

val cameraState = rememberKrossCameraPositionState(
    latitude = 37.7749,
    longitude = -122.4194,
    zoom = 10f,
    tilt = 30f,
    bearing = 45f
)

LaunchedEffect(Unit) {
    cameraState.animateCamera(
        latitude = 34.0522,
        longitude = -118.2437,
        zoom = 12f,
        durationMillis = 1500
    )
}

Clone this wiki locally