13

I have an annotation showing in mapkit with a custom image, showing fine,

but the annotation shows after taping the pin,

how can I have the annotation showing by default?, when I start the view? whit out tapping the pin.

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


    if([annotation isKindOfClass:[MKUserLocation class]])
        return nil; 

    NSString *annotationIdentifier = @"PinViewAnnotation"; 

    MKPinAnnotationView *pinView = (MKPinAnnotationView *) [mapView 
                                                            dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];


    if (!pinView) 
    {
        pinView = [[[MKPinAnnotationView alloc] 
                    initWithAnnotation:annotation 
                    reuseIdentifier:annotationIdentifier] autorelease];

        [pinView setPinColor:MKPinAnnotationColorGreen];
        pinView.animatesDrop = YES; 
        pinView.canShowCallout = YES; 

        UIImageView *houseIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tijereta.png"]];
        pinView.leftCalloutAccessoryView = houseIconView; 
        [houseIconView release];        
    }
    else 
    {
        pinView.annotation = annotation;
    }

    return pinView; 

}

thanks

manuelBetancurt
  • 15,428
  • 33
  • 118
  • 216
  • Do you mean the callout? – yinkou Apr 12 '12 at 13:27
  • hi thanks, I have edited my question to include the code used, please note the canShowCallout, is this what you refer to?, so the image works, but how can I make the annotation show when start the view? – manuelBetancurt Apr 12 '12 at 13:31
  • Your code looks correct, but i don't understand what you mean by "make the annotation show when start the view". Do you want to center the map on it or do you want to programmatically select it to see its callout? – yinkou Apr 12 '12 at 13:50
  • To clarify: An annotation is an object for the map. It will be displayed by an AnnotationView and when you select it map will display a callOutView – yinkou Apr 12 '12 at 13:51
  • If you want the callout (black window) of your annotation to display, you need to call selectAnnotation:animated on your mapView. But this works only if you have exactly one annotation on your mapView. – Cyril Godefroy Apr 12 '12 at 14:01
  • 1
    wrong, it works with infinite annotations. – yinkou Apr 12 '12 at 14:24

1 Answers1

36

you can use this

[mapView selectAnnotation:pinView animated:YES]; //here pinView is your annotation and mapview is your map

hope that helped

Ajeet Pratap Maurya
  • 4,244
  • 3
  • 28
  • 46