Skip to content

Commit

Permalink
feat: Pass Location to onMyLocationClick (#39)
Browse files Browse the repository at this point in the history
Change-Id: Ie01e9fc386316dcbe2bbeb87fc47ec024956fea0
  • Loading branch information
arriolac authored Feb 16, 2022
1 parent 3bfcfcc commit 8c871c4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ private fun GoogleMapView(modifier: Modifier, onMapLoaded: () -> Unit) {
var mapProperties by remember {
mutableStateOf(MapProperties(mapType = MapType.NORMAL))
}
var uiSettings by remember { mutableStateOf(MapUiSettings(compassEnabled = false)) }
var uiSettings by remember {
mutableStateOf(
MapUiSettings(compassEnabled = false)
)
}
var shouldAnimateZoom by remember { mutableStateOf(true) }
var ticker by remember { mutableStateOf(0) }

Expand All @@ -115,7 +119,12 @@ private fun GoogleMapView(modifier: Modifier, onMapLoaded: () -> Unit) {
uiSettings = uiSettings,
onMapLoaded = onMapLoaded,
googleMapOptionsFactory = {
GoogleMapOptions().camera(CameraPosition.fromLatLngZoom(singapore, 11f))
GoogleMapOptions().camera(
CameraPosition.fromLatLngZoom(
singapore,
11f
)
)
},
onPOIClick = {
Log.d(TAG, "POI clicked: ${it.name}")
Expand Down Expand Up @@ -233,11 +242,17 @@ private fun ZoomControls(
Column(verticalArrangement = Arrangement.Center) {
Row(horizontalArrangement = Arrangement.Center) {
Text(text = "Camera Animations On?")
Switch(isCameraAnimationChecked, onCheckedChange = onCameraAnimationCheckedChange)
Switch(
isCameraAnimationChecked,
onCheckedChange = onCameraAnimationCheckedChange
)
}
Row(horizontalArrangement = Arrangement.Center) {
Text(text = "Zoom Controls On?")
Switch(isZoomControlsEnabledChecked, onCheckedChange = onZoomControlsCheckedChange)
Switch(
isZoomControlsEnabledChecked,
onCheckedChange = onZoomControlsCheckedChange
)
}
}
}
Expand All @@ -264,7 +279,8 @@ private fun DebugView(cameraPositionState: CameraPositionState) {
.fillMaxWidth(),
verticalArrangement = Arrangement.Center
) {
val moving = if (cameraPositionState.isMoving) "moving" else "not moving"
val moving =
if (cameraPositionState.isMoving) "moving" else "not moving"
Text(text = "Camera is $moving")
Text(text = "Camera position is ${cameraPositionState.position}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.google.maps.android.compose
import android.content.ComponentCallbacks
import android.content.Context
import android.content.res.Configuration
import android.location.Location
import android.os.Bundle
import android.view.ViewGroup
import android.widget.FrameLayout
Expand Down Expand Up @@ -81,7 +82,7 @@ fun GoogleMap(
onMapLongClick: (LatLng) -> Unit = {},
onMapLoaded: () -> Unit = {},
onMyLocationButtonClick: () -> Boolean = { false },
onMyLocationClick: () -> Unit = {},
onMyLocationClick: (Location) -> Unit = {},
onPOIClick: (PointOfInterest) -> Unit = {},
contentPadding: PaddingValues = NoPadding,
content: (@Composable () -> Unit)? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.google.maps.android.compose

import android.location.Location
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -38,6 +39,6 @@ internal class MapClickListeners {
var onMapLongClick: (LatLng) -> Unit by mutableStateOf({})
var onMapLoaded: () -> Unit by mutableStateOf({})
var onMyLocationButtonClick: () -> Boolean by mutableStateOf({ false })
var onMyLocationClick: () -> Unit by mutableStateOf({})
var onMyLocationClick: (Location) -> Unit by mutableStateOf({})
var onPOIClick: (PointOfInterest) -> Unit by mutableStateOf({})
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal class MapPropertiesNode(
map.setOnMapLongClickListener { clickListeners.onMapLongClick(it) }
map.setOnMapLoadedCallback { clickListeners.onMapLoaded() }
map.setOnMyLocationButtonClickListener { clickListeners.onMyLocationButtonClick() }
map.setOnMyLocationClickListener { clickListeners.onMyLocationClick() }
map.setOnMyLocationClickListener { clickListeners.onMyLocationClick(it) }
map.setOnPoiClickListener { clickListeners.onPOIClick(it) }
map.setOnIndoorStateChangeListener(object : GoogleMap.OnIndoorStateChangeListener {
override fun onIndoorBuildingFocused() {
Expand Down

0 comments on commit 8c871c4

Please sign in to comment.