How to add multiple custom pins to the Pins Ilist in Xamarin.Forms.Maps ?

LSparkLSpark Member ✭✭
edited September 20 in Xamarin.Forms

I'm trying to make a map with custom pins Xamarin.Forms.Maps so I'm following the guide here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/map/customized-pin

At this point the guide creates a single pin, and manually adds it to the Pins IList with Add():

 var pin = new CustomPin { ...
      };

      customMap.CustomPins = new List<CustomPin> { pin };
      customMap.Pins.Add (pin);
      customMap.MoveToRegion (MapSpan.FromCenterAndRadius (
      new Position (37.79752, -122.40183), Distance.FromMiles (1.0)));

What if I have a long list of custom pins though?
I can't write "customMap.Pins = customMap.CustomPins;" because Pins is readable only.
I can't use AddRange() because Pins is an IList.
I tried casting the IList so I could use Addrange but it seems it doesn't work either:

((List<CustomPin>)(customMap.Pins)).AddRange(customMap.CustomPins);

My CustomPin looks like this:

        public class CustomPin : Pin
    {

        [JsonProperty(propertyName: "title")]
        public string Title;
        [JsonProperty(propertyName: "address")]
        public new string Address;
        [JsonProperty(propertyName: "description")]
        public string Description;
        [JsonProperty(propertyName: "pic")]
        public string ImgUrl;
        [JsonProperty(propertyName: "lat")]
        public double Latitude;
        [JsonProperty(propertyName: "lng")]
        public double Longitude;
    }

Is the only way to cycle through the customMap.CustomPins list while using Add() each step?

Best Answer

Answers

  • nnovalbosnnovalbos Member ✭✭
    edited September 22
Sign In or Register to comment.