Hi everyone! I am struggling with GoogleMaps and i...
# compose
p
Hi everyone! I am struggling with GoogleMaps and its snapshot functionality. In order to prepare a google map snapshot we should use the
liteMode
and SnapshotReadyCallback. With this code(code in thread), I am getting crash with error: Bitmap size needs to be more than 0. How can I set the initial size of the googleMap?
Copy code
BoxWithConstraints(
        modifier = Modifier
            .fillMaxWidth()
            .height(200.dp)
    ) {
        val zoomLevel = 11f
        val options = GoogleMapOptions().apply {
            camera(CameraPosition.fromLatLngZoom(location.toGoogleLatLng(), zoomLevel))
            liteMode(true)
        }
        val map = rememberMapViewWithLifecycle(options)
        coroutineScope.launch {
            val googleMap = map.awaitMap()
            googleMap.addMarker { position(location.toGoogleLatLng()) }
            googleMap.snapshot {
                snapshot = it
            }
        }
}
where the snapshot field is:
Copy code
var snapshot by remember {
        mutableStateOf(Bitmap.createBitmap(300, 200, Bitmap.Config.ARGB_8888))
    }
and the ImageView:
Copy code
Image(bitmap = snapshot.asImageBitmap(), contentDescription = "Map snapshot")