Forum Xamarin Xamarin.Forms

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

LSparkLSpark Member ✭✭
edited September 2019 in Xamarin.Forms

I'm trying to make a map with custom pins Xamarin.Forms.Maps so I'm following the guide here:

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:


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


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