Skip to content

Instantly share code, notes, and snippets.

@PiotrPrus
Last active August 13, 2021 12:40
Show Gist options
  • Save PiotrPrus/abb5848d62dc0e5d6bbf261a59109495 to your computer and use it in GitHub Desktop.
Save PiotrPrus/abb5848d62dc0e5d6bbf261a59109495 to your computer and use it in GitHub Desktop.
@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