最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - How to change AdvancedMarker icon in compose Google Maps? - Stack Overflow

programmeradmin2浏览0评论

Google explains how to add markers, they recommend to add them using AdvancedMarker now:

#drawing-on-a-map

GoogleMap(
    googleMapOptionsFactory = {
        GoogleMapOptions().mapId("DEMO_MAP_ID")
    },
    //...
) {
    AdvancedMarker(
        state = MarkerState(position = LatLng(-34, 151)),
        title = "Marker in Sydney"
    )
    AdvancedMarker(
        state = MarkerState(position = LatLng(35.66, 139.6)),
        title = "Marker in Tokyo"
    )
}

The problem is that they don't tell how to change the icon of the AdvancedMarker anywhere in their documentation.

How can I do it? I need to specify a image stored in drawables resource folder.

Google explains how to add markers, they recommend to add them using AdvancedMarker now:

https://github.com/googlemaps/android-maps-compose?tab=readme-ov-file#drawing-on-a-map

GoogleMap(
    googleMapOptionsFactory = {
        GoogleMapOptions().mapId("DEMO_MAP_ID")
    },
    //...
) {
    AdvancedMarker(
        state = MarkerState(position = LatLng(-34, 151)),
        title = "Marker in Sydney"
    )
    AdvancedMarker(
        state = MarkerState(position = LatLng(35.66, 139.6)),
        title = "Marker in Tokyo"
    )
}

The problem is that they don't tell how to change the icon of the AdvancedMarker anywhere in their documentation.

How can I do it? I need to specify a image stored in drawables resource folder.

Share Improve this question edited 2 days ago halfer 20.4k19 gold badges108 silver badges201 bronze badges asked Feb 6 at 19:23 NullPointerExceptionNullPointerException 37.6k80 gold badges230 silver badges402 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can set a drawable resource using a Image and set this image view to the MarkerComposable.

GoogleMap() {
    MarkerComposable(
        state = marker3State,
        onClick = markerClick,
    ) {
        // Customize its content here as your needs
        Column(Modifier.padding(10.dp)) {
            Text(
                text = "Marker 3",
                color = androidx.compose.ui.graphics.Color.Black
            )
            Image(
                painter = painterResource(R.drawable.ic_action_name),
                contentDescription = ""
            )
        }
    }
}

For more details, please go through the documentation of MarkerComposable.

发布评论

评论列表(0)

  1. 暂无评论