can’t get to display all the pins in the following list to the view.
NOTE: my sample below is not part of the xamarin forms documentation . it was my idea that maybe I could combine both lists and display in the map at the same time.
- pin.id==1 (main pin )constant changes its position , trying to add a different image or color
- on loading the map Im trying to display 9 more pins(static-aditional pins ) these ones , wont move. again I assigned a different color of image.
Results, one list overwrites the other one .so either I display pin 1 or the other 9 pins . but I cant put the 10 pins in the screen at the same time.
Heres how to create the first static list and the single pin
public class CustomMap : Map
{
public List<CustomPin> AdditionalPins { get; set; }
public List<CustomPin> CustomPins { get; set; }
public CustomMap()
{
CustomPins = new List<CustomPin>();
AdditionalPins = new List<CustomPin>();
}
var customPin = new CustomPin
{
PinId = 1,
// Position = new Position(37.7749, -122.4194), // Set the position of the pin
Label = "Custom Pin",
Address = "Custom Address",
Rotation = -45 // Set the rotation angle in degrees
};
Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
{
customPin.Position = pos;
// pins.Position = pos;
if (myMap.Pins.Count == 0)
{
myMap.Pins.Add(customPin);
}....
2.set of static pins
foreach (var coordinate in coordinates)
{
var poss = new Position(coordinate.Latitude, coordinate.Longitude);
CustomPin additionalPin = new CustomPin
{
PinId = 20,
Label = "Additional Pin",
Name = coordinate.StopNumber
// Add more properties as needed
};
myMap.AdditionalPins.Add(additionalPin);
Now, I do get both of the lists one have 1 pin that its updating its position every 10 seconds and the other one (adittionalpins =9 set of coordinates)
protected override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
{
if (annotation is MKUserLocation)
return null;
var result = GetAllPins(annotation as MKPointAnnotation); //HERE -- get all the items
if (result != null)
{
List<CustomPin> pins = result;
if (pins != null && pins.Any())
{
foreach (var D in pins)
{
if (annotationView == null)
{
annotationView = new MKAnnotationView(annotation, reuseIdentifier);
if (D.PinId == 1) //it gets here the first time
{
annotationView.Image = UIImage.FromFile("lilocation.png");
}
else if (D.PinId == 20) //never assign this part to the view
{
annotationView.Image = UIImage.FromFile("red.png");
}
}
}
}
return annotationView;
}
Goal, is to display every single item in the list with its image and behavior . THE ISSUE is the view only gets null the first time.




