Skip to content

Instantly share code, notes, and snippets.

@hkawii
Created June 5, 2021 14:53
Show Gist options
  • Save hkawii/d1f92814cdcb113697c6ffc5155e5e92 to your computer and use it in GitHub Desktop.
Save hkawii/d1f92814cdcb113697c6ffc5155e5e92 to your computer and use it in GitHub Desktop.
@Composable
private fun MapViewContainer(
isEnabled: Boolean,
mapView: MapView,
viewModel: MapViewModel
) {
AndroidView(
factory = { mapView }
) {
mapView.getMapAsync { map ->
map.uiSettings.setAllGesturesEnabled(isEnabled)
val location = viewModel.location.value
val position = LatLng(location.latitude, location.longitude)
map.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 15f))
map.setOnCameraIdleListener {
val cameraPosition = map.cameraPosition
viewModel.updateLocation(cameraPosition.target.latitude, cameraPosition.target.longitude)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment