我在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);
答案 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();
}