3

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
gabrjan
  • 3,080
  • 9
  • 40
  • 69

1 Answers1

6

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

  1. MKPinAnnotationColorGreen;
  2. MKPinAnnotationColorPurple
  3. 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;
}
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70