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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:27:44+00:00 2026-06-04T12:27:44+00:00

I have A MapView with multiple annotations. I need to put different images to

  • 0

I have A MapView with multiple annotations. I need to put different images to annotations according to string value in my data.plist

My current code (work just for one category, one image):

NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];

    NSArray *anns = [dict objectForKey:@"Category1"];
    pinView.image = [UIImage imageNamed:[[anns objectAtIndex:0] objectForKey:@"Icon"]];

    pinView.canShowCallout=YES;

My plist file construction:

plist

EDIT

My MapViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];


    NSMutableArray *annotations = [[NSMutableArray alloc]init];


    NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];


    NSArray *anns = [dict objectForKey:@"Category1"];

    NSLog(@" MapView is %@",mapView);
    NSLog(@"anns is: %@", anns);



    for(int i = 0; i < [anns count]; i++) {


        NSString *coordinates = [[anns objectAtIndex:i] objectForKey:@"Coordinates"];

        double realLatitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:1] doubleValue];
        double realLongitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:0] doubleValue];

        MyAnnotation *myAnnotation = [[MyAnnotation alloc] init];
        CLLocationCoordinate2D theCoordinate;
        theCoordinate.latitude = realLatitude;
        theCoordinate.longitude = realLongitude;


        //calculate distance
        CLLocationCoordinate2D annocoord = myAnnotation.coordinate;
        CLLocationCoordinate2D usercoord = self.mapView.userLocation.coordinate;

        NSLog(@"ANNO  = %f, %f", annocoord.latitude, annocoord.longitude);
        NSLog(@"USER = %f, %f", usercoord.latitude, usercoord.longitude);

        CLLocation *loc = [[CLLocation alloc] initWithLatitude:myAnnotation.coordinate.latitude longitude:myAnnotation.coordinate.longitude];
        CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:self.mapView.userLocation.coordinate.latitude longitude:self.mapView.userLocation.coordinate.longitude];

        NSLog(@"LOC  = %f, %f", loc.coordinate.latitude,  loc.coordinate.longitude);
        NSLog(@"LOC2 = %f, %f", loc2.coordinate.latitude, loc2.coordinate.longitude);

        CLLocationDistance dist = [loc distanceFromLocation:loc2];

        NSLog(@"DIST: %f", dist); 

        myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude);        
        myAnnotation.title = [[anns objectAtIndex:i] objectForKey:@"Name"];
        myAnnotation.subtitle = [NSString stringWithFormat:@"%.f", dist];


        [mapView addAnnotation:myAnnotation];
        [annotations addObject:myAnnotation];
    }


    NSArray *alko = [dict objectForKey:@"Category2"];

    NSLog(@" MapView is %@",mapView);
    NSLog(@"alko is: %@", alko);


    for(int i = 0; i < [alko count]; i++) {


        NSString *coordinates = [[alko objectAtIndex:i] objectForKey:@"Coordinates"];

        double realLatitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:1] doubleValue];
        double realLongitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:0] doubleValue];

        MyAnnotation *myAnnotation = [[MyAnnotation alloc] init];
        CLLocationCoordinate2D theCoordinate;
        theCoordinate.latitude = realLatitude;
        theCoordinate.longitude = realLongitude;

        myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude);        
        myAnnotation.title = [[alko objectAtIndex:i] objectForKey:@"Name"];
        myAnnotation.subtitle = [[alko objectAtIndex:i] objectForKey:@"Address"];


        [mapView addAnnotation:myAnnotation];
        [annotations addObject:myAnnotation];
    }





    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [self.locationManager startUpdatingLocation];

}

Annotation

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


    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;


    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
    MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc]
                                    initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];


    NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];

    NSArray *anns = [dict objectForKey:@"Category1"];
    pinView.image = [UIImage imageNamed:[[anns objectAtIndex:0] objectForKey:@"Icon"]];

    pinView.canShowCallout=YES;


    return pinView;
}
  • 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-04T12:27:45+00:00Added an answer on June 4, 2026 at 12:27 pm

    Is this what you need?

    NSString *theCategory;
    
    // set theCategory to what you need.
    theCategory = @"Category1"
    
    NSArray *anns = [dict objectForKey:theCategory];
    

    Edit 1

    First you’d better set the annotation class as following:

    MyAnnotation.h

    #import <MapKit/MapKit.h>
    
    @interface MyAnnotation : NSManagedObject <MKAnnotation>{
    
    CLLocationCoordinate2D coordinate;
    UIImage *imageForMyAnnotation;
    }
    
    @property (nonatomic,readwrite) CLLocationCoordinate2D coordinate;
    @property (nonatomic, retain) UIImage *imageForMyAnnotation;
    

    MyAnnotation.m

    #import "MyAnnotation.h"
    
    @implementation MyAnnotation
    
    - (CLLocationCoordinate2D)coordinate
    {
    //here you can set the coordinate of your annotation
    return coordinate;
    }
    
    - (UIImage *)imageForMyAnnotation{
    //set the image here, i think it is depend on the coordinate right? You can put some code here to chose the category that corresponding to the coordinate
    return image;
    }
    
    // optional
    - (NSString *)title
    {
    return title;
    }
    - (NSString *)subtitle
    {
    return subtitle;
    }
    

    Then in your mapView, you can add the annotation with

    MapView.m

    [self.mapView addAnnotations:myAnnotationArray];
    

    or

    [self.mapView addAnnotation:myAnnotation];
    

    and

    - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation{
    
    UIImageView *annotationImageView = [[UIImageView alloc] initWithImage: myAnnotation.imageForMyAnnotatioin]; 
    
    customPinView.leftCalloutAccessoryView = annotationImageView;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have A MapView with Multiple annotations. But I need to put different images
I have multiple annotations on the map - although the user may need to
I have a mapview with several annotations. Every annotation has a leftCalloutAccessoryView which is
HI, I have a Mapview with some marker points + a marker for current
I have an Android MapView in which i need to have a second layer
i have a mapView with pins on it, and the following code for CLLocation
I have a mapview where I want to track the user's current location. GPS
I have a mapview and i put an annotation which shows a custom title
I have a MapView onto which I put some overlays (MKPolygon). I have to
I have a mapview with many annotations on it. When the user clicks on

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.