Skip to content

Instantly share code, notes, and snippets.

@arriolac
Created May 16, 2022 16:47
Show Gist options
  • Save arriolac/605e91242dd0b8068f968e37b3e375a6 to your computer and use it in GitHub Desktop.
Save arriolac/605e91242dd0b8068f968e37b3e375a6 to your computer and use it in GitHub Desktop.
Maps Compose Snippets
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
val singapore = LatLng(1.35, 103.87)
val cameraPositionState = rememberCameraPositionState {
position = CameraPosition.fromLatLngZoom(singapore, 11f)
}
Box(Modifier.fillMaxSize()) {
GoogleMap(
modifier = Modifier.matchParentSize(),
cameraPositionState = cameraPositionState
)
val coroutineScope = rememberCoroutineScope()
Button(onClick = {
coroutineScope.launch {
cameraPositionState.animate(
CameraUpdateFactory.zoomIn()
)
}
}) {
Text(text = "Zoom in")
}
}
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
GoogleMap(modifier = Modifier.fillMaxSize()) {
Marker(
state = MarkerState(LatLng(1.35, 103.87)),
title = "Marker in Singapore",
onClick = { Log.d("Marker", "Marker was clicked") }
)
}
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
GoogleMap(
properties = MapProperties(isBuildingEnabled = true)
// …
)
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
MyAppTheme {
GoogleMap(
//
) {
Circle(
center = singapore,
fillColor = MaterialTheme.colors.primary
)
}
}
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
GoogleMap(
uiSettings = MapUiSettings(compassEnabled = false, mapToolbarEnabled = true)
// …
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment