sahithi
sahithi

Reputation: 1089

How to remove marker on map

I have created a marker as below in my activity.

public async void OnMapReady(GoogleMap googleMap)
    {

        MarkerList = new List<Marker>();

        LatLng latLng = new LatLng(16.022,40.3033);

        CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngZoom(latLng, 10);
        googleMap.MoveCamera(cameraUpdate);

        MarkerOptions markerOptions = new MarkerOptions();
        markerOptions.Draggable(false);
        markerOptions.SetPosition(latLng);
        googleMap.AddMarker(markerOptions);
        Marker M = googleMap.AddMarker(markerOptions);
        MarkerList.Add(M);

        googleMap.MarkerDragEnd += GoogleMap_MarkerDragEnd;

       // googleMap.SetInfoWindowAdapter(this);
       // googleMap.UiSettings.ZoomControlsEnabled = true;
       // googleMap.UiSettings.CompassEnabled = true;
        googleMap.MoveCamera(CameraUpdateFactory.ZoomTo(150));

    }

And on other event I need to remove those markers for that i coded like as below.

foreach(Marker marker in MarkerList)
{
   marker.Remove();
   marker.Visible=false;//this is also not working
}

But there is no change on map. How to remove those markers on map?

Upvotes: 0

Views: 537

Answers (1)

sahithi
sahithi

Reputation: 1089

I got it worked with the small change

Insted of this:

googleMap.AddMarker(markerOptions);
Marker M = googleMap.AddMarker(markerOptions);

I placed as following:

Marker M = googleMap.AddMarker(markerOptions);

and it got worked.

Upvotes: 1

Related Questions