Place a Marker on center of the screen on Jetpack compose map

In this article we will learn How to place a marker on center of the screen on Jetpack compose map.

Place marker on center of the screen on compose map android same as like in uber and ola apps. When moving or scrolling a google map marker should not move and it should give latlng coordinates.

Whether the camera is currently moving or not. This includes any kind of movement: panning, zooming, or rotation.

cameraPositionState.isMoving

..

Current position of the camera on the map.

cameraPositionState.position

..

@Composable
fun ComposeMapCenterPointMapMarker() {
    val markerPosition = LatLng(1.35, 103.87)
    val cameraPositionState = rememberCameraPositionState {
        position = CameraPosition.fromLatLngZoom(markerPosition, 18f)
    }
    GoogleMap(
        modifier = Modifier.fillMaxSize(),
        cameraPositionState = cameraPositionState
    )
        Column(
            modifier = Modifier.fillMaxSize(),
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.Center
        ) {
            IconButton(
                onClick = {
                },
            ) {
                Image(
                    painter = painterResource(id = R.drawable.pin2),
                    contentDescription = "marker",
                )
            }
            Text(text = "Is camera moving: ${cameraPositionState.isMoving}" +
                    "\n Latitude and Longitude: ${cameraPositionState.position.target.latitude} " +
                    "and ${cameraPositionState.position.target.longitude}",
                textAlign = TextAlign.Center
            )
        }
}

..

GET source code on Github:

..

Comments