diff --git a/app/src/main/java/com/google/maps/android/compose/CustomControlsActivity.kt b/app/src/main/java/com/google/maps/android/compose/CustomControlsActivity.kt index 1efae7d76..525d67c90 100644 --- a/app/src/main/java/com/google/maps/android/compose/CustomControlsActivity.kt +++ b/app/src/main/java/com/google/maps/android/compose/CustomControlsActivity.kt @@ -39,6 +39,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp + class CustomControlsActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -46,7 +47,9 @@ class CustomControlsActivity : ComponentActivity() { setContent { var isMapLoaded by remember { mutableStateOf(false) } - val mapProperties by remember { mutableStateOf(MapProperties(isMyLocationEnabled = true)) } + // This needs to be manually deactivated to avoid having a custom and the native + // location button + val uiSettings by remember { mutableStateOf(MapUiSettings(myLocationButtonEnabled = false)) } // Observing and controlling the camera's state can be done with a CameraPositionState val cameraPositionState = rememberCameraPositionState { position = defaultCameraPosition @@ -59,17 +62,16 @@ class CustomControlsActivity : ComponentActivity() { onMapLoaded = { isMapLoaded = true }, - - myLocationButton = { - MapButton( - "This is a custom location button", - onClick = { - Toast.makeText( - this@CustomControlsActivity, - "Click on my location", - Toast.LENGTH_SHORT - ).show() - }) + uiSettings = uiSettings, + ) + MapButton( + "This is a custom location button", + onClick = { + Toast.makeText( + this@CustomControlsActivity, + "Click on my location", + Toast.LENGTH_SHORT + ).show() }) if (!isMapLoaded) { diff --git a/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt b/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt index da27b1225..8aae82d1f 100644 --- a/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt +++ b/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt @@ -20,7 +20,6 @@ import android.location.Location import android.os.Bundle import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.Row import androidx.compose.runtime.Composable import androidx.compose.runtime.Composition import androidx.compose.runtime.CompositionContext @@ -88,7 +87,6 @@ public fun GoogleMap( onMyLocationClick: ((Location) -> Unit)? = null, onPOIClick: ((PointOfInterest) -> Unit)? = null, contentPadding: PaddingValues = NoPadding, - myLocationButton: (@Composable @GoogleMapComposable () -> Unit)? = null, content: (@Composable @GoogleMapComposable () -> Unit)? = null, ) { // When in preview, early return a Box with the received modifier preserving layout @@ -119,16 +117,11 @@ public fun GoogleMap( val currentContentPadding by rememberUpdatedState(contentPadding) // If we pass a custom location button, the native one is deactivated. - val currentUiSettings by rememberUpdatedState(if (myLocationButton != null) { - uiSettings.copy(myLocationButtonEnabled = false) - } else { - uiSettings - }) + val currentUiSettings by rememberUpdatedState(uiSettings) val currentMapProperties by rememberUpdatedState(properties) val parentComposition = rememberCompositionContext() val currentContent by rememberUpdatedState(content) - val currentLocation by rememberUpdatedState(myLocationButton) LaunchedEffect(Unit) { disposingComposition { @@ -150,10 +143,6 @@ public fun GoogleMap( } } } - Row(modifier = modifier) { - currentLocation?.invoke() - } - } internal suspend inline fun disposingComposition(factory: () -> Composition) {