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 8842325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:55:43+00:00 2026-06-14T10:55:43+00:00

I’m trying to show a annotation callout right after the mapview loads. I’m sure

  • 0

I’m trying to show a annotation callout right after the mapview loads. I’m sure I’m missing a simple thing but can’t find it.

thanks for any help.

here’s my code:

my .h:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface MapDetailViewController : UIViewController <MKMapViewDelegate> {

    MKMapView *mapView;

}


// map
@property (strong, nonatomic) IBOutlet MKMapView *mapView;

@property (nonatomic) double latDouble;
@property (nonatomic) double lngDouble;

@property (nonatomic) NSString *vendorStr;

@property (nonatomic) NSNumber *costAmount;


@end

my .m:

#import “MapDetailViewController.h”

@interface MapDetailViewController ()

@end

#define THESPAN 0.01f;

@implementation MapDetailViewController
@synthesize mapView;
@synthesize latDouble, lngDouble;
@synthesize vendorStr, costAmount;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

}

-(void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:YES];

   // mapView.showsUserLocation = YES;
    mapView.delegate = self;

    MKCoordinateRegion region;

    MKCoordinateSpan span;
    span.longitudeDelta = THESPAN;
    span.latitudeDelta = THESPAN;

    CLLocationCoordinate2D annotationCoord;
    annotationCoord.latitude = latDouble;
    annotationCoord.longitude = lngDouble;


    MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
    annotationPoint.coordinate = annotationCoord;
    annotationPoint.title = vendorStr;

    //convert cost amount/ price to string value for the subtitle
    NSString *costAmountStr = [costAmount stringValue];


    annotationPoint.subtitle = costAmountStr;
    [mapView addAnnotation:annotationPoint];


    region.center = annotationCoord;
    region.span = span;

    [mapView setRegion:region animated:YES];


}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKPinAnnotationView *newAnnotation=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotation1"];

    UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [disclosureButton addTarget:self action:@selector(mapCallOutPressed:) forControlEvents:UIControlEventTouchUpInside];

    newAnnotation.rightCalloutAccessoryView = disclosureButton;
    newAnnotation.animatesDrop = YES;    
    newAnnotation.canShowCallout = YES;
    newAnnotation.annotation = annotation;
    newAnnotation.draggable = YES;
    newAnnotation.enabled = YES;
    newAnnotation.exclusiveTouch = YES;
    newAnnotation.highlighted = YES;
    newAnnotation.multipleTouchEnabled = YES;
    newAnnotation.pinColor = MKPinAnnotationColorRed;
    newAnnotation.userInteractionEnabled = YES;


    //button on the right for popup for pins
        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    [rightButton addTarget:self
                    action:@selector(mapCallOutPressed:)
          forControlEvents:UIControlEventTouchUpInside];
    newAnnotation.rightCalloutAccessoryView = rightButton;


    //Create and add the right button to the callout
    UIButton* rightCalloutButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    rightCalloutButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [newAnnotation setRightCalloutAccessoryView:rightButton];


    //zoom button on the left of popup for pins
    UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
    [leftButton setTitle:annotation.title forState:UIControlStateNormal];
    [leftButton addTarget:self
                   action:@selector(zoomToLocation:) forControlEvents:UIControlEventTouchUpInside];
    newAnnotation.leftCalloutAccessoryView = leftButton;

    UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tag.png"]];
    newAnnotation.leftCalloutAccessoryView = profileIconView;


    return newAnnotation;
}


- (void)mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views{
    for (id<MKAnnotation> currentAnnotation in mapView.annotations) {
            [mapView selectAnnotation:currentAnnotation animated:YES];

    }
}

// method for the annotation detail disclosure button
-(void)mapCallOutPressed:(id)sender {

    NSLog(@"mapcallout pressed");

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
  • 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-06-14T10:55:44+00:00Added an answer on June 14, 2026 at 10:55 am

    You should dispatch the [MKMapView selectAnnotation:animated:] method with with a slight delay when calling it from mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views

    - (void)mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views{
        int64_t delayInSeconds = 0.1;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            for (id<MKAnnotation> currentAnnotation in mapView.annotations) {
                [mapView selectAnnotation:currentAnnotation animated:YES];
    
            }
        });
    }
    

    * EDIT

    Tried on a 6.0.1 device, 6.0 and 5.1 simulator. It definitely works, I suspect you’re not setting your annotation title properly by passing nil.

    Try changing the title to a fix value as follows:

    annotationPoint.title = @"Hello world";
    

    * EDIT2:

    Your property declaration should probably look more like

    @property (nonatomic, copy) NSString *vendorStr;
    @property (nonatomic, strong) NSNumber *costAmount;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.