question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Polyline doesn't recompose when points change

See original GitHub issue

Environment details

Android API 26 com.google.maps.android:maps-compose:2.1.0

Steps to reproduce

  1. Create a map with a MutableStateList of points
  2. Use the points to draw markers and a polyline between them
  3. Add functionality to add or remove points from the list
  4. Observe that the markers update, but the polyline does not

Code example

@Composable
fun MapScreen(){
    val waypoints = remember{ mutableStateListOf<LatLng>()}
    Map(waypoints) {
        waypoints.add(it)
    }
}

@Composable
private fun Map(
    waypoints: List<LatLng>,
    modifier: Modifier = Modifier,
    onMapClicked: (latlng: LatLng) -> Unit
){
    GoogleMap(
        modifier = modifier,
        onMapClick = onMapClicked,
    ){
        waypoints.forEach {
            Marker(state = MarkerState(position = it))
        }
        Polyline(waypoints)
    }
}

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
arriolaccommented, May 11, 2022

I believe the issue might be between the interaction of mutableStateListOf and a ComposeNode’s Updater. Because Polyline as currently implemented should work. I’ve opened an issue in the public issue tracker for Compose here: https://issuetracker.google.com/issues/232271525

0reactions
Sergiysscommented, Aug 16, 2022

Is the question still open? Help me. the last Polyline is not updated, but markers are drawn according to the route.

@Composable
fun MapScreen(){
  val path  = chvm.pathResult.observeAsState()
    var waypoints by remember{ mutableStateOf<List<LatLng>>(value = listOf())}

    if(path.value?.path?.size != null){
        Map(path.value?.path!!) {
            waypoints = waypoints + it
        }
    }
}

@Composable
private fun Map(
    waypoints: List<LatLng>,
    modifier: Modifier = Modifier,
    onMapClicked: (latlng: LatLng) -> Unit
){
    GoogleMap(
        modifier = modifier,
        onMapClick = onMapClicked,
    ){
        waypoints.forEach {
            Marker(state = MarkerState(position = it))
        }
        Polyline(waypoints)
    }
}

Screenshot_202

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does the Composable for the route recompose when ...
I was thinking that it only changed the Composable where the State ... that contains (reads) State will recompose when the State changes....
Read more >
Visible Polygon Vertices - Troubleshooting
I think I'm just repeating what Andy Broomell suggested. -after decomposing the polyline change the start/stop end conditions to a point. A ...
Read more >
Gathering points defining 3D AutoCAD geometry using .NET
Here's the updated C# code – the main changes are at the beginning of the CollectPoints() function, where I've added the handling of...
Read more >
[Solved]-Google maps won't recompose Android-kotlin
You need to provide an update callback.The AndroidView recomposes whenever a State read within the callback changes. @Composable fun CustomView() { val ...
Read more >
copy and mirror polyline in vbscript?
1. at each start point of the line, mirror a copy from its start point ... movements of the system as the internal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found