Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,24 @@ Adding a map to your app looks like the following:

```kotlin
val singapore = LatLng(1.35, 103.87)
val cameraPositionState = rememberCameraPositionState {
position = CameraPosition.fromLatLngZoom(singapore, 10f)
}
GoogleMap(
modifier = Modifier.fillMaxSize(),
googleMapOptionsFactory = {
GoogleMapOptions().camera(CameraPosition.fromLatLngZoom(singapore, 10f))
}
cameraPositionState = cameraPositionState
)
```

### Creating and configuring a map

Configuring the map can be done either by passing a `GoogleMapOptions` instance
to initialize the map, or by passing a `MapProperties` object into the `GoogleMap`
composable.
Configuring the map can be done by passing a `MapProperties` object into the
`GoogleMap` composable. For anything not available in `MapProperties` (typically
anything that can only be provided once - like map ID), provide a
`GoogleMapOptions` instance in the `googleMapOptionsFactory` properties instead.

```kotlin
// Initialize map by providing a googleMapOptionsFactory
GoogleMap(
googleMapOptionsFactory = {
GoogleMapOptions().mapId("MyMapId")
}
)

// ...or set properties using MapProperties which you can use to recompose the map
// Set properties using MapProperties which you can use to recompose the map
var mapProperties by remember {
mutableStateOf(
MapProperties(maxZoomPreference = 10f, minZoomPreference = 5f)
Expand All @@ -59,12 +54,26 @@ Box(Modifier.fillMaxSize()) {
Text(text = "Toggle isBuildingEnabled")
}
}

// ...or initialize the map by providing a googleMapOptionsFactory
// This should only be used for values that do not recompose the map such as
// map ID.
GoogleMap(
googleMapOptionsFactory = {
GoogleMapOptions().mapId("MyMapId")
}
)

```

### Controlling a map's camera

Camera changes and updates can be observed and controlled via `CameraPositionState`.

**Note**: `CameraPositionState` is the source of truth for anything camera
related. So, providing a camera position in `GoogleMapOptions` will be
overridden by `CameraPosition`.

```kotlin
val singapore = LatLng(1.35, 103.87)
val cameraPositionState: CameraPositionState = rememberCameraPositionState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ private fun GoogleMapView(modifier: Modifier, onMapLoaded: () -> Unit) {
properties = mapProperties,
uiSettings = uiSettings,
onMapLoaded = onMapLoaded,
googleMapOptionsFactory = {
GoogleMapOptions().camera(
CameraPosition.fromLatLngZoom(
singapore,
11f
)
)
},
onPOIClick = {
Log.d(TAG, "POI clicked: ${it.name}")
}
Expand Down