ManthanDalal
ManthanDalal

Reputation: 1073

How to display Annotation view without clicking on pin in mapview?

I have implemented one map application in which i have display pin animation for current location.When i click on the pin at that time annotation view will open. But i want to display annotation view without clicking on pin.Is it possible if possible then please give me idea about that.

Thanks in advance.

Upvotes: 5

Views: 2083

Answers (3)

Kinka
Kinka

Reputation: 425

Try out:

It seems that [mapView selectAnnotation:annotation animated:YES] works too.

Hope this helps.

Upvotes: 5

Satya
Satya

Reputation: 3330

We can show the annotation with out clicking on it. Use the following code:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
     static NSString *identifier = @"Pin";

    MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
    pin.canShowCallout = YES;
    [pin setSelected:YES animated:NO];

    return [pin autorelease];
}

Upvotes: -2

Bj&#246;rn Marschollek
Bj&#246;rn Marschollek

Reputation: 10009

You just need to find your MKAnnotationView instance you want to select and call -setSelected:animated:.

For example, you can loop your annotations of an MKMapView like this:

for (YOURCLASSHERE *a in mapView.annotations) {
    // Your current position (if shown) is an annotation as well. Thus check for the right class!
    if ([a isKindOfClass:[YOURCLASSHERE class]]) {
        // insert some smart if statement here, if you have multiple annotations!
        [[mapView viewForAnnotation:a] setSelected:YES animated:YES];
    }
}

YOURCLASSHERE is your class which implements the MKAnnotation protocol.

Of course the loop is superfluous if you already know your annotationView.

Upvotes: 2

Related Questions