I am use the Xamarin iOS MKMapView, and i am trying to have separate images for each pin, but when I override the GetViewForAnnotation method, it makes all the pins the same image, is there a way to make every pin a different image.
class MapDelegate : MKMapViewDelegate
{
static string annotationId = "CustomAnnotation";
UIImageView venueView;
UIImage venueImage;
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation)
{
MKAnnotationView annotationView = null;
if (annotation is MKUserLocation)
return null;
if (annotation is CustomAnnotation) {
// show conference annotation
annotationView = mapView.DequeueReusableAnnotation (annotationId);
if (annotationView == null)
annotationView = new MKAnnotationView (annotation, annotationId);
UIImage image = ImageSource.FromFile("image.png");
}
return annotationView;
}
public override MKOverlayView GetViewForOverlay (MKMapView mapView, NSObject overlay)
{
// return a view for the polygon
MKPolygon polygon = overlay as MKPolygon;
MKPolygonView polygonView = new MKPolygonView (polygon);
polygonView.FillColor = UIColor.Blue;
polygonView.StrokeColor = UIColor.Red;
return polygonView;
}
}
And the constructor:
map.MapType = MKMapType.Standard;
map.ShowsUserLocation = true;
map.ZoomEnabled = true;
map.ScrollEnabled = true;
map.DidUpdateUserLocation += (sender, ex) => {
if (map.UserLocation != null) {
CLLocationCoordinate2D userLocation = map.UserLocation.Coordinate;
MKCoordinateSpan range = new MKCoordinateSpan(MilesToLatitudeDegrees(5), MilesToLongitudeDegrees(5, userLocation.Latitude));
MapDelegate mapDelegate = new MapDelegate();
map.Delegate = mapDelegate;
/*ADDING MULTIPLE ANNOTATIONS HERE*/
}
}
}
};
I want to set each annotation to a different custom pin image, can someone help THANK YOU.