How to display annotation view without clicking on a contact in mapview?

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

Thanks in advance.

+3
source share
3 answers

Try:

It seems [mapView selectAnnotation:annotation animated:YES]to work too.

Hope this helps.

+4
source

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

For example, you can encode MKMapView annotations as follows:

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 - , MKAnnotation.

, , .

+2

We can show the annotation without 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];
}
-2
source

Source: https://habr.com/ru/post/1778915/


All Articles