本文介绍了在Google Map v2中拖动时,如何实时更新标记位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在Google Map中拖动标记时,我想实时更新标记位置,并在标记上方的文本中显示它.
现在,通过工具void onMarkerDragEnd(Marker marker)
结束拖动后,我只能更新标记的位置,但是在地图中拖动标记时,不能更新位置.
那么在地图上拖动标记时如何更新或知道标记位置?
When I drag the marker in Google Map, I want to update the marker location in realtime and show it in text up the marker.
Now I can just update marker location when end the dragging by implement void onMarkerDragEnd(Marker marker)
, but can't update the location when I am dragging the marker in map.
So how can I update or know marker location when I am dragging it in map?
推荐答案
您可以为此使用onMarkerDrag().请参见下面的示例.
You can use onMarkerDrag() for that..See the below given example..
marker=Mmap.addMarker(new MarkerOptions().position(currentpos)
.title("Draggable Marker")
.snippet("Long press and move the marker if needed.")
.draggable(true)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.mark_start)));
Mmap.setOnMarkerDragListener(new OnMarkerDragListener() {
@Override
public void onMarkerDrag(Marker arg0) {
// TODO Auto-generated method stub
Log.d("Marker", "Dragging");
LatLng markerLocation = marker.getPosition();
Log.d("MarkerPosition", markerLocation.toString());
}
@Override
public void onMarkerDragEnd(Marker arg0) {
// TODO Auto-generated method stub
LatLng markerLocation = marker.getPosition();
Toast.makeText(MainActivity.this, markerLocation.toString(), Toast.LENGTH_LONG).show();
Log.d("Marker", "finished");
}
@Override
public void onMarkerDragStart(Marker arg0) {
// TODO Auto-generated method stub
Log.d("Marker", "Started");
}
});
这篇关于在Google Map v2中拖动时,如何实时更新标记位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!