Skip to content

Instantly share code, notes, and snippets.

@PiotrPrus
Last active August 13, 2021 12:40
Embed
What would you like to do?
@Composable
fun GoogleMapSnapshot(location: LatLng) {
Box(
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
) {
val mapView = rememberMapViewWithLifecycle()
MapViewContainer(
map = mapView,
location = location
)
}
}
@Composable
private fun MapViewContainer(
map: MapView,
location: LatLng
) {
val coroutineScope = rememberCoroutineScope()
AndroidView({ map }) { mapView ->
coroutineScope.launch {
val googleMap = mapView.awaitMap()
val zoom = calculateZoom(cameraPosition)
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, zoom))
googleMap.addMarker { position(cameraPosition) }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment