[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting contentPadding offset the cameraPosition #142

Open
HugoAlberto opened this issue Jun 9, 2022 · 2 comments
Open

Setting contentPadding offset the cameraPosition #142

HugoAlberto opened this issue Jun 9, 2022 · 2 comments
Assignees
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@HugoAlberto
Copy link

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 HugoAlberto added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jun 9, 2022
@Dante313
Copy link

@HugoAlberto Hey. Have you find a solution?

@anqus
Copy link
anqus commented Nov 7, 2022

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
    )
  }

@kikoso kikoso added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed triage me I really want to be triaged. labels Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

5 participants