0

I'm having a little trouble, I want a marker to appear on the map each loop at the new position and remove the old marker however the old markers are still there, I thought the options.visible(false); would remove it however they still remain visible.

public void newTimer(final polyline route)
{
    new CountDownTimer(30000, 1000)
    {
        int i = 0;
        MarkerOptions options = new MarkerOptions();
        public void onTick(long millisUntilFinished)
        {
                i++;
                options.visible(false);
                 options =new MarkerOptions()
                    .position(route.getPositions().get(i))
                    .visible(true)
                    .icon(BitmapDescriptorFactory
                    .defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
                mMap.addMarker(options);
        }

        public void onFinish() {
            Log.d("Remaining time: ","0");
        }
    }.start();
Tainted
  • 15
  • 3

1 Answers1

1

Instead of creating a new marker just update the position.

private Marker myMarker = null;
if (myMarker == null)
    myMarker = mMap.addMarker(new MarkerOptions())
                    .position(route.getPositions().get(i))
                    .icon(BitmapDescriptorFactory
                    .defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
else
  myMarker.setPosition(route.getPositions().get(i));