Xamarin - Android.GoogleMap删除标记

时间:2017-07-21 03:02:36

标签: c# google-maps xamarin google-maps-api-3

我在Xamarin表单中使用Android.Gms.Maps.GoogleMap包,我似乎无法找到删除Marker实例的函数。我已在[{1}}中保存了对我Marker中所有List<Marker>的引用,并需要定期删除它们以用新的Marker替换它们

这是我的代码:

var markerOptions = new MarkerOptions();
markerOptions.Draggable(false);
markerOptions.SetTitle(userLocations[i].user_id);
markerOptions.SetPosition(new LatLng(Convert.ToDouble(latLongs.latitude), Convert.ToDouble(latLongs.longitude)));
markerOptions.SetSnippet("Latitude: " + Convert.ToDouble(latLongs.latitude) + " Longitude: " + Convert.ToDouble(latLongs.longitude));
markerOptionsList.Add(markerOptions); //List<Marker>
map.AddMarker(markerOptions);

1 个答案:

答案 0 :(得分:2)

map.AddMarker()返回一个Marker对象。如果要删除Marker,则必须将其存储在列表中以供参考。删除功能只是marker.Remove();

创建标记列表:

List<Marker> marketList = new List<Marker>;

添加标记:

var markerOptions = new MarkerOptions();
markerOptions.Draggable(false);
markerOptions.SetTitle(userLocations[i].user_id);
markerOptions.SetPosition(new LatLng(Convert.ToDouble(latLongs.latitude), Convert.ToDouble(latLongs.longitude)));
markerOptions.SetSnippet("Latitude: " + Convert.ToDouble(latLongs.latitude) + " Longitude: " + Convert.ToDouble(latLongs.longitude));
Marker M = map.AddMarker(markerOptions);
markerList.Add(M);

删除标记:

 foreach (Marker m in markerList)
 {
     m.Remove();
 }