如何获取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
相关产品推荐
相关产品推荐

