android-maps-compose icon indicating copy to clipboard operation
android-maps-compose copied to clipboard

Setting contentPadding offset the cameraPosition

Open HugoAlberto opened this issue 3 years ago • 1 comments

Hi,

When adding a contentPadding to the Google map, the map's cameraPosition is never centered on the screen :

image

The default marker is the position given to the map and the little work icon is at the center of the screen with the same map paddings.

Environment details

Android Maps Compose version : 2.2.1

Code example

val bottomSheetPadding = remember { PaddingValues(bottom = 40.dp) }
val cameraPositionState = rememberCameraPositionState {
    position = CameraPosition.fromLatLngZoom(LatLng(0.0, 0.0), 17f)
}
GoogleMap(
    modifier = modifier.fillMaxSize(),
    cameraPositionState = cameraPositionState,
    contentPadding = bottomSheetPadding
) {
    Marker(state = rememberMarkerState(position = LatLng(0.0, 0.0)))
}

Image(
    painter = painterResource(ic_work),
    contentDescription = null,
    modifier = Modifier
        .align(Center)
        .padding(bottomSheetPadding)
        .padding(bottom = 24.dp) // Icon size /2
        .size(48.dp)
)

Thanks!

HugoAlberto avatar Jun 09 '22 12:06 HugoAlberto

@HugoAlberto Hey. Have you find a solution?

Dante313 avatar Aug 11 '22 13:08 Dante313

The best solution I have found is to run this whenever the padding has changed:

  suspend fun onMapPaddingChanged() {
    cameraPositionState.animate(
      CameraUpdateFactory
        .newCameraPosition(
          cameraPositionState.position
        ),
      durationMs = 250
    )
  }

anqus avatar Nov 07 '22 10:11 anqus