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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:50:50+00:00 2026-05-27T10:50:50+00:00

will this code when working show custom pins and logos or just 1 pin

  • 0

will this code when working show custom pins and logos or just 1 pin with custom logos? please see plist below, only error is Local declaration of mapView hides instance variable.

<plist version="1.0">
<array>
<dict>
    <key>stationIdKey</key>
    <string>BP</string>
    <key>stationNameKey</key>
    <string>Atkinson Dam Cabin Village</string>
    <key>stationAddressKey</key>
    <string>Atkinson Dam Road, Atkinson Dam</string>
    <key>stationLatitudeKey</key>
    <string>-27.415056</string>
    <key>stationLongitudeKey</key>
    <string>152.43057</string>
</dict>
<dict>
    <key>stationIdKey</key>
    <string>Shell</string>
    <key>stationNameKey</key>
    <string>BP - AYR DCA</string>
    <key>stationAddressKey</key>
    <string>108 Edwards Street, AYR</string>
    <key>stationLatitudeKey</key>
    <string>-19.57094107</string>
    <key>stationLongitudeKey</key>
    <string>147.4025662</string>
</dict>

and the mapViewController.m file

- (void)viewDidload
{

    [super viewDidLoad];

NSString *path = [[NSBundle mainBundle] pathForResource:@"stations" ofType:@"plist"];
NSArray *anns = [NSArray arrayWithContentsOfFile:path];
NSLog(@"anns=%@",anns);

for(NSMutableDictionary *note in anns) {
    float realLatitude = [[note objectForKey:@"stationLatitudeKey"] floatValue];
    float realLongitude = [[note objectForKey:@"stationLongitudeKey"] floatValue];        
    MyAnnotation* myAnnotation = [[MyAnnotation alloc] init];
    CLLocationCoordinate2D theCoordinate;
    theCoordinate.latitude = realLatitude;
    theCoordinate.longitude = realLongitude;
    myAnnotation.coordinate = theCoordinate;
    myAnnotation.title = [note objectForKey:@"stationNameKey"];
    myAnnotation.subtitle = [note objectForKey:@"stationAddressKey"];
    myAnnotation.stationIdKey = [note objectForKey:@"stationIdKey"];
    [mapView setDelegate:self];
    [mapView addAnnotation:myAnnotation];
    [myAnnotation release];        
} }



-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{  if ([annotation isKindOfClass:[MyAnnotation class]])
{
    static NSString *reuseId = @"customAnn";

    MKAnnotationView *customAnnotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
    if (customAnnotationView == nil)
    {
        customAnnotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId] autorelease];
        UIImage *pinImage = [UIImage imageNamed:@"pin-green.png"];
        [customAnnotationView setImage:pinImage];
        customAnnotationView.canShowCallout = YES;
        UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        customAnnotationView.rightCalloutAccessoryView = rightButton;
    }

    NSString *iconFilename = @"";
    MyAnnotation *myAnn = (MyAnnotation *)annotation;
    if ([myAnn.stationIdKey isEqualToString:@"BP"])
        iconFilename = @"bp-logo.png";
    else
        if ([myAnn.stationIdKey isEqualToString:@"Caltex"])
            iconFilename = @"caltex.png";
        else
            if ([myAnn.stationIdKey isEqualToString:@"Shell"])
                iconFilename = @"shell.png";
    UIImageView *leftIconView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:iconFilename]] autorelease];
    customAnnotationView.leftCalloutAccessoryView = leftIconView;

    customAnnotationView.annotation = annotation;

    return customAnnotationView; 
}

return nil; }


-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{ if ([view.annotation isKindOfClass:[MyAnnotation class]])
{
    MyAnnotation *myAnn = (MyAnnotation *)view.annotation;
    NSLog(@"callout button tapped for station id %@", myAnn.stationIdKey);
}
else
{
    NSLog(@"callout button tapped for annotation %@", view.annotation);
} }
  • 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-27T10:50:50+00:00Added an answer on May 27, 2026 at 10:50 am

    (Posting a separate answer for the slightly modified question. The original question was how to change the annotation callout image based on some property of the annotation object. The modified question is why the annotations are not appearing at all based on the latest code and how to fix the warning in viewForAnnotation.)

    The only obvious problem with the latest code in the question is that the viewDidLoad method is spelled wrong which prevents that code from getting called at all. Please change this:

    - (void)viewDidload  //the lowercase "l" is not correct, must be uppercase
    

    to this:

    - (void)viewDidLoad
    

    A few other things to check just in case:

    • Plist file should really be like <?xml ...><!DOCTYPE ...><plist ...><array><dict>xxx</dict><dict>yyy</dict><dict>zzz</dict></array></plist>
    • Make sure the image files like pin-green.png, etc have been added to the project and are named exactly that way (uppercase/lowercase matters on the device)

    Next, to fix the compiler warning in viewForAnnotation, change the name of the mapView parameter to something else so it’s different from the mapView ivar in the view controller. Following example changes it to aMapView (two places marked with ^^^^^^):

    -(MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id<MKAnnotation>)annotation
                                              ^^^^^^^^
    {  
        if ([annotation isKindOfClass:[MyAnnotation class]])
        {
            static NSString *reuseId = @"customAnn";
    
            MKAnnotationView *customAnnotationView = [aMapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
                                                      ^^^^^^^^
            if (customAnnotationView == nil)
            {
                customAnnotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId] autorelease];
                UIImage *pinImage = [UIImage imageNamed:@"pin-green.png"];
                [customAnnotationView setImage:pinImage];
                customAnnotationView.canShowCallout = YES;
                UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                customAnnotationView.rightCalloutAccessoryView = rightButton;
            }
    
            NSString *iconFilename = @"";
            MyAnnotation *myAnn = (MyAnnotation *)annotation;
            if ([myAnn.stationIdKey isEqualToString:@"BP"])
                iconFilename = @"bp-logo.png";
            else
                if ([myAnn.stationIdKey isEqualToString:@"Caltex"])
                    iconFilename = @"caltex.png";
                else
                    if ([myAnn.stationIdKey isEqualToString:@"Shell"])
                        iconFilename = @"shell.png";
            UIImageView *leftIconView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:iconFilename]] autorelease];
            customAnnotationView.leftCalloutAccessoryView = leftIconView;
    
            customAnnotationView.annotation = annotation;
    
            return customAnnotationView; 
        }
    
        return nil; 
    }
    

    This is how it looks (your pin and callout images may be different):

    Green Pins

    Shell Callout

    Caltex Callout

    BP Callout

    If you want the pins themselves to have different images instead of their callouts, then in viewForAnnotation, call setImage instead of setting the leftCalloutAccessoryView.

    Another minor, unrelated, thing is that you don’t need to call mapView setDelegate inside the for-loop. You only need to call it once before the for-loop (and if you’ve already connected the map view’s delegate to File’s Owner in the xib, you don’t need to do it in code at all).

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

Sidebar

Related Questions

from this code will show in original color how can i change it to
I must warn you, this code will hurt your eyes, so please don't judge
Will this code ever wait on the mutex inside the producer's void push(data) ?
I am unsure why this code will not work. When I click a button
var nextRow = tbl.tBodies[0].rows.length; var row = tbl.tBodies[0].insertRow(nextRow); row.setAttribute('ondblclick', return move_to_x_graph();); This code will
I have this code which will include template.php file from inside each of these
I have the this code that will create excel file and work sheet then
If I run this code, will each AppDomain execute in a different thread? ThreadPool.QueueUserWorkItem(delegate
In a View, code like this will generate the right URL to jump to
I am trying to write a simple tool using Shoes. This will indent code

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.