'Get current location button is not show on the jetpack compose google map
I want to show the current location button (isMyLocationButtonEnabled) on the Google Map but it's not showing.
How can I display the get current location button?
AndroidView(
factory = { mapView }
) {
mapView.getMapAsync { map ->
map.apply {
navigatorViewModel.apply {
viewModelScope.launch {
isMapEditable.collectLatest {
uiSettings.setAllGesturesEnabled(
it,
)
uiSettings.isMyLocationButtonEnabled = true
}
}
val location = lastSelectedLocation.value
val position = LatLng(location.latitude, location.longitude)
moveCamera(
CameraUpdateFactory.newLatLngZoom(
position,
Constants.ZOOM_CAMERA
)
)
setOnCameraIdleListener {
val cameraPosition = map.cameraPosition
updateLocation(
cameraPosition.target.latitude,
cameraPosition.target.longitude
)
}
}
}
}
}
Solution 1:[1]
I'm replying so late, this answer might help someone else!
To show MyLocationButton in google map you need enable both
map.isMyLocationEnabled = true & uiSettings.isMyLocationButtonEnabled = true
Solution 2:[2]
Add these properties:
val uiSettings = remember {
MapUiSettings(myLocationButtonEnabled = true)
}
val properties by remember {
mutableStateOf(MapProperties(isMyLocationEnabled = true))
}
GoogleMap:
GoogleMap(
modifier = modifier.fillMaxSize(),
cameraPositionState = cameraPositionState,
properties = properties,
uiSettings = uiSettings)
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 | Kunal Sharma |
| Solution 2 | Sadegh.t |
