0

This is a very simple question, I figured I could just do something like this to make a custom image show up instead of the pin but it's not working. Any help? Thank you!

  - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {


self.pinAnnotation = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"personAnnotation"];

//    self.pinAnnotation.pinColor = self.pinColor;

self.pinAnnotation.image = [UIImage imageNamed:@"myImage"];

self.pinAnnotation.animatesDrop = YES;

return self.pinAnnotation;

 }
kb920
  • 3,039
  • 2
  • 33
  • 44
Echizzle
  • 3,359
  • 5
  • 17
  • 28
  • Check this http://stackoverflow.com/questions/9814988/mkmapview-instead-of-annotation-pin-a-custom-view – kb920 Jan 29 '16 at 06:27

2 Answers2

0

I just find this before

  - (MKAnnotationView *)mapView:(MKMapView *)map 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:@"location.png"];
    annotationView.annotation = annotation;

    return annotationView;
}
Mohamed Helmy
  • 821
  • 1
  • 9
  • 20
0

To use your own image for an annotation view, you should create an MKAnnotationView instead of an MKPinAnnotationView.

So try below code:

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation 
{
    MKAnnotationView *pinView = nil; 
    if(annotation != mapView.userLocation) 
    {
        static NSString *AnnotationViewID = @"annotationViewID";
        pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
        if ( pinView == nil ) 
            pinView = [[MKAnnotationView alloc]
                                         initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];

        //pinView.pinColor = MKPinAnnotationColorGreen; 
        pinView.canShowCallout = YES;
        //pinView.animatesDrop = YES;
        pinView.image = [UIImage imageNamed:@"myImage.jpg"];
    } 
    else {
        //user location
    }
    return pinView;
}

animatesDrop is also commented out since that property only exists in MKPinAnnotationView.

Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51