Created
August 13, 2021 14:02
-
-
Save PiotrPrus/2c60b2a31dbba63ae662094c79960a3f 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 MapSnapshot(map: MapView, location: LatLng) { | |
val mapBitmap: MutableState<Bitmap?> = remember { mutableStateOf(null) } | |
val coroutineScope = rememberCoroutineScope() | |
if (mapBitmap.value != null) { | |
Image( | |
bitmap = mapBitmap.value!!.asImageBitmap(), | |
contentDescription = "Map snapshot", | |
) | |
} else { | |
AndroidView({ map }) { mapView -> | |
coroutineScope.launch { | |
val googleMap = mapView.awaitMap() | |
val zoom = calculateZoom() | |
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, zoom)) | |
googleMap.addMarker { position(location) } | |
googleMap.snapshot { | |
mapBitmap.value = it | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment