Xamarin.Forms.GoogleMaps icon indicating copy to clipboard operation
Xamarin.Forms.GoogleMaps copied to clipboard

Remove custom Pins

Open mcferdev opened this issue 6 years ago • 6 comments

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.

mcferdev avatar Oct 09 '18 17:10 mcferdev

I also tried on MainThread.

The Pins are beeing removed from the List, but doesn´t disappear from the map.

mcferdev avatar Oct 10 '18 13:10 mcferdev

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

amay077 avatar Oct 17 '18 11:10 amay077

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 !

mcferdev avatar Oct 19 '18 01:10 mcferdev

Didn´t work. The pins are being removed from the list, but the pins image keep displayed. I also tried the map.Pins.Clear()

mcferdev avatar Oct 22 '18 13:10 mcferdev

This bug was fixed !! Please, check it to update this one.

https://github.com/xamarin/Xamarin.Forms/issues/2411

mcferdev avatar Dec 04 '18 13:12 mcferdev

Alternative solution can be to save the pins you want to keep in a seperate variable and use Pins.Clear(), this works.

deltecequipment avatar Nov 06 '20 09:11 deltecequipment