How to change marker icon?

ios, mapkit, objective-c

Solution

you can use 3 types of color pins in mapView are bellow..

- `MKPinAnnotationColorGreen;`

- `MKPinAnnotationColorPurple`

- `MKPinAnnotationColorRed`

and if you want to add customview or image then you can add with programatically

also you can change pin in delegate method of `MKMapView` like bellow..

- (MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{
 MKPinAnnotationView *pinView  = (MKPinAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
        if (annotation == _mapView.userLocation) 
        {
//            pinView.pinColor = MKPinAnnotationColorRed;
//            return pinView;
            return nil;
        }
        pinView.pinColor = MKPinAnnotationColorGreen; // you can use MKPinAnnotationColorPurple, MKPinAnnotationColorRed;
        pinView.canShowCallout = YES;
        pinView.animatesDrop = NO;

        return pinView;
}

and for custom image or pin, use bellow code..

- (MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{
    static NSString *AnnotationViewID = @"annotationViewID";

    MKAnnotationView *annotationView = (MKAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
    }

    annotationView.image = [UIImage imageNamed:@"yourImageName"];//add any image which you want to show on map instead of red pins
    annotationView.annotation = annotation;

    return annotationView;
}

Problem

I was wonderring if there is a way to change those red pins that are used as markers. And if there is a way, how to do it?

Original source