When i add two or more pins, i have exaption: "[0:] An error occurred: 'Object reference not set to an instance of an object.'. Callstack: ' at TestApp.iOS.CustomMapRenderer.GetCustomPin (MapKit.MKPointAnnotation annotation) [0x0001f] in C:\Users\Admin\source\repos\TestApp\TestApp\TestApp.iOS\CustomMapRenderer.cs:114 "
Code when create exaption:
CustomPin GetCustomPin(MKPointAnnotation annotation)
{
var position = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude);
foreach (var pin in customPins)
{
if (pin.Position == position)
{
return pin;
}
}
return null;
}
My code, when i add pins:
public MapPage()
{
InitializeComponent();
CustomPin pin = new CustomPin
{
Type = PinType.Place,
Position = new Position(37.79752, -122.40183),
Label = "Xamarin San Francisco Office",
Address = "394 Pacific Ave, San Francisco CA",
Name = "Xamarin",
Url = "http://xamarin.com/about/"
};
CustomPin pin2 = new CustomPin
{
Type = PinType.Place,
Position = new Position(40.79752, -122.40183),
Label = "Xamarin San Francisco Office",
Address = "394 Pacific Ave, San Francisco CA",
Name = "Xamarin",
Url = "http://xamarin.com/about/"
};
customMap.CustomPins = new List<CustomPin> { pin, pin2 };
customMap.Pins.Add(pin);
customMap.Pins.Add(pin2);
customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(37.79752, -122.40183), Distance.FromMiles(1.0)));
}
