Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initial Camera Position Google Maps Compose

I'm trying to use the new Google Maps Compose functions to add a map, but I can't get it to set the initial camera position. For testing purposes, the lat and lon are equal to Mountain View, CA, and zoom is 5:

GoogleMap(
        googleMapOptionsFactory = {
            GoogleMapOptions()
                .camera(
                    CameraPosition.fromLatLngZoom(
                        LatLng(lat.toDouble(), lon.toDouble()),
                        zoom.toFloat()
                    )
                )
        },
        modifier = Modifier.fillMaxSize()
    )

It just shows a map with the camera centered at 0, 0.

like image 428
Ralgha Avatar asked Sep 12 '25 00:09

Ralgha


1 Answers

Well, I solved it, but it still leaves questions. The googleMapOptions().camera seems to be completely useless. I had to do this:

GoogleMap(
        cameraPositionState = rememberCameraPositionState {
            position = CameraPosition.fromLatLngZoom(LatLng(lat.toDouble(), lon.toDouble()), zoom.toFloat())
        },
        modifier = Modifier.fillMaxSize()
    )

That works, having the googleMapOptions().camera in there seems to do nothing at all, so I'm still confused as to its purpose.

like image 154
Ralgha Avatar answered Sep 14 '25 23:09

Ralgha