views:

75

answers:

1

I am able to load a big list of location onto my MapKit and display them all with a custom Pin image and annotation.

The issue i'm having is that I currently have all annotations displaying the same Title, Subtitle, and pinImage.

How do I make it so that I can set each annotation with its own Title and different Pin image? I'm having a hard time trying to identify what annotation is being setup via mapView:viewForAnnotation.

- (NSString *)subtitle{

    return @"This is the annotation subtitle.";
}

- (NSString *)title{
    return @"Annotations Title";
}

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if (annotation == mapView.userLocation) {
        return nil;
    }

    MKAnnotationView *annView=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    UIImage *pinImage = [UIImage imageNamed:@"mapPin.png"];
    annView.image = pinImage;
    return annView;
}
+1  A: 

You'll need to cast the annotation object to your custom type and access it's properties to appropriately change the annotationView that you return.

Apple's WeatherMap sample project is a good example of how to do this. https://developer.apple.com/library/ios/#samplecode/WeatherMap/Introduction/Intro.html

The MapCallouts sample project is the same idea, but a simpler implementation. https://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html

Robot K
Hey, thanks a ton. I got my app working with a combination of the two and I got it doing more then I originally planned. Thanks.
MikesTooLz