mapkit show annotation by default

2020-06-09 04:30发布

问题:

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

回答1:

you can use this

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

hope that helped