You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取Jetpack Compose中可拖拽Marker的新坐标?

获取Google Map Marker拖拽结束后的新坐标

你可以通过给Marker添加onDragEnd回调函数来获取拖拽结束后的坐标,这个回调会在用户停止拖拽Marker时触发,参数就是拖拽后的LatLng位置。

修改后的代码示例:

Marker(
    state = MarkerState(
        position = LatLng(lat, lng)
    ),
    title = "Party",
    snippet = "Come to party.",
    draggable = true,
    // 添加拖拽结束回调
    onDragEnd = (LatLng newPosition) {
        // 这里可以获取到拖拽后的新坐标
        print("拖拽后的纬度: ${newPosition.latitude}");
        print("拖拽后的经度: ${newPosition.longitude}");
        // 你可以在这里把新坐标保存到变量或者做其他处理
    },
)

说明

  • onDragEnd是Marker的可选参数,接收一个LatLng类型的参数,就是拖拽完成后的最终位置。
  • 你可以在回调函数里直接使用这个newPosition,比如更新状态变量、保存到本地或者发送到服务器。

内容的提问来源于stack exchange,提问作者Always Learner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 15:22:34