Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the new coordinates of draggable marker in Jetpack Compose?

I have the following marker that is added successfully on a Google Map:

Marker(
    state = MarkerState(
        position = LatLng(lat, lng)
    ),
    title = "Party",
    snippet = "Come to party.",
    draggable = true
)

I set this marker to be draggable and it works, but how to know the new coordinated when the marker is dropped?

like image 225
Joan P. Avatar asked Sep 16 '25 22:09

Joan P.


1 Answers

I think this can be done by remembering the marker state you are passing to the Marker; for instance, you can write the following code and query the state for the new coordinates or pass that state to where you want to get the updates:

val markerState = rememberMarkerState(position = LatLng(lat, lng))
Marker(
    state = markerState
    title = "Party",
    snippet = "Come to party.",
    draggable = true
)

That way, on every recomposition, upon dragging the marker, the new position will be in the markerState.

I hope this helps!

like image 78
Younes Charfaoui Avatar answered Sep 19 '25 13:09

Younes Charfaoui