Xamarin.Forms.GoogleMaps
Xamarin.Forms.GoogleMaps copied to clipboard
Remove custom Pins
VERSIONS
- Xamarin.Forms.GoogleMaps - 3.0.4
- Xamarin.Forms - 3.2.0
PLATFORMS
- [x] Android
- [ ] iOS
- [ ] UWP
ACTUAL BEHAVIOR
map.Pins.Remove(item) not working.
I tried the Code below:
for (int index = 0; index < listaApreensaoFuzil.Count(); index++)
{
try
{
var item = listaApreensaoFuzil[index];
var obj = item.latlng;
var LATLONG = JsonConvert.DeserializeObject<LatLong>(obj);
listaApreensaoFuzil[index].Latlong = LATLONG;
pinApreensaoFuzil.Address = listaApreensaoFuzil[index].NmInformacao;
pinApreensaoFuzil.Position = new Position(listaApreensaoFuzil[index].Latlong.Lat, listaApreensaoFuzil[index].Latlong.Lng);
map.Pins.Remove(pinApreensaoFuzil);
}
catch (Exception ex)
{
}
This code with Add instead of Remove, works nicelly. After, I click to Remove, but nothing happens. Even, a error, don´t happen.
EXPECTED BEHAVIOR
Pins removed.
I also tried on MainThread.
The Pins are beeing removed from the List, but doesn´t disappear from the map.
Is listaApreensaoFuzil
pins collection?
for (int index = 0; index < listaApreensaoFuzil.Count(); index++)
{
var item = listaApreensaoFuzil[index];
map.Pins.Remove(item);
}
Or this is remove all pins.
var pins = map.Pins.Select(x => x); // using System.Linq;
foreach (var p in pins)
{
map.Pins.Remove(p);
}
Is
listaApreensaoFuzil
pins collection?for (int index = 0; index < listaApreensaoFuzil.Count(); index++) { var item = listaApreensaoFuzil[index]; map.Pins.Remove(item); }
Or this is remove all pins.
var pins = map.Pins.Select(x => x); // using System.Linq; foreach (var p in pins) { map.Pins.Remove(p); }
Yes, it is.
On monday I will give a try. I am off now... but thanks !
Didn´t work. The pins are being removed from the list, but the pins image keep displayed. I also tried the map.Pins.Clear()
This bug was fixed !! Please, check it to update this one.
https://github.com/xamarin/Xamarin.Forms/issues/2411
Alternative solution can be to save the pins you want to keep in a seperate variable and use Pins.Clear(), this works.