Davis
Davis

Reputation: 1263

How to zoom in on annotation click WITHOUT open the annotationView?

I'm using the Apple maps. At the moment I have to click on one of my Annotation Pins and the Annotation View is opening, than I can click on this view and something happens. But i want to click on my Annotation Pins and the Map should be zoom in WITHOUT opening the Annotation View first. I tried this, but it doesn't work:

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

if(someValues > 1){
    //If someValues are bigger than one then only zoom in without returning the annotation View

    MKCoordinateRegion region = mapView.region;
    MKCoordinateSpan span;
    span.latitudeDelta = region.span.latitudeDelta/5;
    span.longitudeDelta = region.span.longitudeDelta/5;
    region.span = span;
    region.center = anntotation.coordinate;
    [mapView setRegion:region animated:TRUE];

//return 0 returns a default view i know....whats correct?
    return 0;

} else {


MKPinAnnotationView *view = nil;

if (annotation != mapView.userLocation) 
{
    view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"identifier"];

    if (nil == view) {
        view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"identifier"];
    }
    [view setPinColor:MKPinAnnotationColorRed];
    view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [view setCanShowCallout:YES];
    [view setAnimatesDrop:NO];

}
    return view;
}
}

Is there any delegate Method i´m missing?

Upvotes: 1

Views: 433

Answers (1)

DjimOnDev
DjimOnDev

Reputation: 399

please see the didSelectAnnotationView delegate method to your mapview.

example :

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
    if([[view annotation]  isKindOfClass:[myMarker class]]) return;
} 

And here :

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if([[view annotation]  isKindOfClass:[myMarker class]]) return nil;
}

Upvotes: 1

Related Questions