Skip to content Skip to sidebar Skip to footer

How Can I Update Marker Location In Real Time When Dragging In Google Map V2?

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 draggin

Solution 1:

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

            }
        });

Post a Comment for "How Can I Update Marker Location In Real Time When Dragging In Google Map V2?"