如何在地图上删除标记

时间:2018-11-03 05:12:18

标签: google-maps xamarin.android

我在活动中创建了一个标记,如下所示。

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

    }

在其他情况下,我需要删除我编码的那些标记,如下所示。

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

但是地图上没有变化。如何在地图上删除这些标记?

1 个答案:

答案 0 :(得分:1)

我通过很小的改动就可以使用

为此:

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

我的位置如下:

Marker M = googleMap.AddMarker(markerOptions);

成功了。

相关问题