Initial Camera Position Google Maps Compose

Viewed 997

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.

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.

Related