Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:46:58+00:00 2026-05-29T21:46:58+00:00

Im trying to show a callout when user taps on an overlay. The callout

  • 0

Im trying to show a callout when user taps on an overlay. The callout then has a title on it based on the selected overlay. I want the annotations to be shown only when users taps on an overlay. but the problem is that the overlay doesnt recognize the tap and all the annotations are visible at start. I want them hidden.

a similiar question is here. but I cant figure it out.
Show callout when tapping overlay

overlays coordinations are downloaded from the server and added like this:

 //Add a polygon
        MKPolygon *rect=[MKPolygon polygonWithCoordinates:parkingCords count:5];
        [self.mapView addOverlay:rect];
        [self.mapView addAnnotation:rect];

Each overlay has now an Annotation in its centre.

ViewForAnnotation

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

...
 else if([annotation isKindOfClass:[MKPolygon class]]){
        NSLog(@"MKPOLYGON CLASS");
        static NSString *identifier3 = @"else";  
        MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier3];


        if (annotationView == nil) {
            annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier3];
            annotationView.enabled = YES;
            annotationView.canShowCallout = YES;

        } else {
            annotationView.annotation = annotation;

        } 
...
}

viewForOverlay

 -(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay{
        if([overlay isKindOfClass:[MKPolygon class]]){
            MKPolygonView *view = [[MKPolygonView alloc] initWithOverlay:overlay];
            view.lineWidth=1;
            view.strokeColor=[UIColor blueColor];
            view.fillColor=[[UIColor blueColor] colorWithAlphaComponent:0.3];

            recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(overlayTapped)]; 
            recognizer.delegate=self;
            [view addGestureRecognizer:recognizer];
            [recognizer release];

            return view;
        }
        return nil;
    }


-(void)overlayTapped{

    NSLog(@"overlay tapped");
    //[self.mapView setSelectedAnnotations:?????];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:46:59+00:00Added an answer on May 29, 2026 at 9:46 pm

    I’ve solved whit this code:

    After you had determinate the span region

     CLLocation *userLoc = myMapView.userLocation.location;
        CLLocationCoordinate2D userCoordinate = userLoc.coordinate;
        NSLog(@"user latitude = %f",userCoordinate.latitude);
        NSLog(@"user longitude = %f",userCoordinate.longitude);
        myMapView.delegate=self;
    
    
        NSMutableArray* annotations=[[NSMutableArray alloc] init];
    
        //vallee
        CLLocationCoordinate2D theCoordinate1;
        theCoordinate1.latitude = 45.752453;
        theCoordinate1.longitude = 7.642313;
        //venezia
        CLLocationCoordinate2D theCoordinate2;
        theCoordinate2.latitude = 45.442793;
        theCoordinate2.longitude = 12.329691;
        //campione
        CLLocationCoordinate2D theCoordinate3;
        theCoordinate3.latitude = 45.971027;
        theCoordinate3.longitude = 8.971362;
        //sanremo
        CLLocationCoordinate2D theCoordinate4;
        theCoordinate4.latitude = 43.814910;
        theCoordinate4.longitude = 7.772050;
    
        myAnnotation* myAnnotation1=[[myAnnotation alloc] init];
    
        myAnnotation1.coordinate=theCoordinate1;
        myAnnotation1.title=@"Casinò della Vallée";
        myAnnotation1.subtitle=@"Saint Vincent";
    
        myAnnotation* myAnnotation2=[[myAnnotation alloc] init];
    
        myAnnotation2.coordinate=theCoordinate2;
        myAnnotation2.title=@"Casinò di Venezia";
        myAnnotation2.subtitle=@"Venezia";
    
        myAnnotation* myAnnotation3=[[myAnnotation alloc] init];
    
        myAnnotation3.coordinate=theCoordinate3;
        myAnnotation3.title=@"Casinò di Campione";
        myAnnotation3.subtitle=@"Campione";
    
        myAnnotation* myAnnotation4=[[myAnnotation alloc] init];
    
        myAnnotation4.coordinate=theCoordinate4;
        myAnnotation4.title=@"Casinò di Sanremo";
        myAnnotation4.subtitle=@"Sanremo";
    
    
        [myMapView addAnnotation:myAnnotation1];
        [myMapView addAnnotation:myAnnotation2];
        [myMapView addAnnotation:myAnnotation3];
        [myMapView addAnnotation:myAnnotation4];
    
    
        //[annotations addObject:myAnnotation1];
        [annotations addObject:myAnnotation2];
        [annotations addObject:myAnnotation3];
        [annotations addObject:myAnnotation4];
    
    
        NSLog(@"%d",[annotations count]);
    
    
    
    }
    
    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation {
        if (annotation == mapView.userLocation) {
            return nil;
        }
        MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
        pinView.pinColor = MKPinAnnotationColorGreen;
        pinView.canShowCallout = YES;
        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    
        pinView.animatesDrop = YES;
        return pinView;
    }
    
    //disclosure button con indicazioni
    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    
        [self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];
    
          //street from here to there
    
        NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
    
            NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];  
            [[UIApplication sharedApplication] openURL:url];
    
    
    
    }
    

    Wishing this code useful

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to show a activity indicatorvw when user taps on the cell
Trying to show a label only when a certain item in a combo is
I'm trying to show a div when a user clicks in an input field,
I am trying to show the user's location obtained using geolocation API on google
Trying to show ProgressDialog, but getting: Can't create handler inside thread that has not
Im trying to show a list of views for the logged in user. The
I'm trying to show a dialog with a google map, when the user clicks
I'm trying to show a notification of success before redirecting the user to another
I'm trying to get an MKMapView to show a pin with a callout bubble.
I'm trying to show a Toast Message when user click on a Button inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.