'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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Khantahr |
