how to remove pins from the map?

0

I am developing a multiplatform application in xamarin with google maps, to start I used the next xamarin sample.

Sample custom renderer

The only thing that I have added to that example is that the values of the pins are given dynamically in a foreach taking the values of a webservice, everything else is exactly the same as the example, everything works well up there.

Now I need to implement a button to remove all the pins from the map, I have been trying different ways a week and I do not achieve it, what I really need is to update the pins but to update them I need to delete them first.

What happens after pressing the button keeps the pins on the screen but pressing one of the pins produces a nullreference exception, therefore I think they are effectively removed from the list but not from the view.

The code of my button is as follows.

bActualizar.Clicked += async (sender, e) =>
        {
            for (int x = 0; x < customMap.Pins.Count; x++)
            {
                customMap.Pins.RemoveAt(x);
                customMap.Pins.Remove(customMap.Pins[x]);
            }
            for (int x = 0; x < customMap.CustomPins.Count; x++)
            {
                customMap.CustomPins.RemoveAt(x);
                customMap.CustomPins.Remove(customMap.CustomPins[x]);
            }

        };
    
asked by Medina Nualart Martin 09.10.2017 в 00:17
source

0 answers