Last active
August 13, 2021 12:40
-
-
Save PiotrPrus/abb5848d62dc0e5d6bbf261a59109495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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