myanmarking
03/29/2022, 5:41 PMposition = CameraPosition.fromLatLngZoom, which internally do CameraUpdateFactory.newCameraPosition(value) but i would like to use CameraUpdateFactory.newLatLngBoundsmyanmarking
03/29/2022, 5:41 PMMike
03/29/2022, 9:08 PMcameraPositionState into the GoogleMap composable and call cameraPositionState.move(yourBounds) inside onMapLoaded of the GoogleMap composable. If the bounds can change, you can call the same move function from where the new bounds get createdMike
03/29/2022, 9:09 PMvar isMapLoaded by remember { mutableStateOf(false) }
val cameraPositionState = rememberCameraPositionState()
val mapWidth: Int
val mapHeight: Int
with(LocalDensity.current) {
mapWidth = maxWidth.roundToPx()
mapHeight = maxHeight.roundToPx()
}
val bounds = remember(currentLocation, mapMarkers) {
getCameraUpdateForBounds(currentLocation, mapMarkers, mapWidth, mapHeight)?.apply {
if (isMapLoaded) {
cameraPositionState.move(this)
}
}
}
GoogleMap(
modifier = modifier,
cameraPositionState = cameraPositionState,
onMapLoaded = {
isMapLoaded = true
bounds?.let {
cameraPositionState.move(it)
}
}
)myanmarking
03/29/2022, 10:03 PM