How can I update marker location in real time when dragging in Google Map v2?

StackOverflow https://stackoverflow.com/questions/23590050

  •  19-07-2023
  •  | 
  •  

Вопрос

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?

Это было полезно?

Решение

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");

            }
        });
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top