Jetpack组合谷歌地图按钮自定义



我正在使用新的库为jetpack撰写谷歌地图implementation "com.google.maps.android:maps-compose:1.0.0"尝试自定义我的按钮,我想更改它的位置和图标。

这是我初始化GoogleMap((的代码

@Composable
private fun GoogleMapView(hasPermission: Boolean, modifier: Modifier, onMapLoaded: () -> Unit) {
val defaultCamera = LatLng(42.6977, 23.3219)
val cameraPositionState = rememberCameraPositionState {
position = CameraPosition.fromLatLngZoom(defaultCamera, 11f)
}
var properties by remember { mutableStateOf(MapProperties(isMyLocationEnabled = hasPermission)) }
var uiSettings by remember { mutableStateOf(MapUiSettings(zoomControlsEnabled = false)) }
val context = LocalContext.current
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager

GoogleMap(
modifier = modifier,
cameraPositionState = cameraPositionState,
properties = properties,
uiSettings = uiSettings,
onMapLoaded = onMapLoaded,
googleMapOptionsFactory = {
GoogleMapOptions().camera(CameraPosition.fromLatLngZoom(defaultCamera, 11f))
},
onMyLocationButtonClick = {
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
) {
buildAlertMessageNoGps(context)
return@GoogleMap true
}
return@GoogleMap false
}
)
}

这是我想要实现的自定义按钮。使用较旧的方式,我只是将mapView作为自变量,但在这里我不知道如何获得它。

private fun setupMyLocationButton(mapView: com.google.android.libraries.maps.MapView) {
val buttonName = "GoogleMapMyLocationButton"
val locationButton: ImageView =
mapView.findViewWithTag(buttonName)
locationButton.setImageResource(R.drawable.ic_gps_btn)
val rlp = locationButton.layoutParams as? (RelativeLayout.LayoutParams)
rlp?.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0)
rlp?.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE)
rlp?.setMargins(
0, 0, 30, 30
)
}

官方文件->https://developers.google.com/maps/documentation/android-sdk/maps-compose

这在Maps Compose库中目前是不可能的。我建议在这里提交一个功能请求:https://github.com/googlemaps/android-maps-compose/issues/new?assignees=&labels=类型%3A+功能+请求%2C+分类+我&template=feature_request.md&title=

相关内容

  • 没有找到相关文章

最新更新