简体   繁体   中英

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.

Try out:

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

Hope this helps.

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.

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM