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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:15:17+00:00 2026-05-23T06:15:17+00:00

ok desperation. This is killing me.. I totally do not understand MapKit at all..

  • 0

ok desperation. This is killing me.. I totally do not understand MapKit at all.. Despite reading so many tutorial.. =(

For more information, I have 2 annotation classes – MyAnnotation and MyAnnotation2, it doesnt seems to work too.. Somebody plz help.. I am afraid I have no hair left soon =(

- (void)viewWillAppear:(BOOL)animated
{

[super viewWillAppear:animated];


_annotations = [[NSMutableArray alloc] init];
_annotation2 = [[NSMutableArray alloc] init];

CLLocation *userLoc = _mapView.userLocation.location;
CLLocationCoordinate2D userCoordinate = userLoc.coordinate;

NSLog(@"user latitude = %f",userCoordinate.latitude);
NSLog(@"user longitude = %f",userCoordinate.longitude);


_listOfPolyClinics = [[NSMutableArray alloc] init];
_listOfPatients = [[NSMutableArray alloc] init ];



for (PolyClinics *polyclinics in [[PatientDatabase database] 
                                  polyClinics]){
    [_listOfPolyClinics addObject:polyclinics];
}
NSLog(@"%i", [_listOfPolyClinics count]);

for (PatientDetails *patientDetails in [[PatientDatabase database] 
                                        patientCategoryList:_category]){
    [_listOfPatients addObject:patientDetails];
}

NSLog(@"%i", [_listOfPatients count]);




for (PolyClinics *polyclinics in _listOfPolyClinics){
    MyAnnotation * myAnnotation =[[MyAnnotation alloc] init];

    CLLocationCoordinate2D theCoordinate;
    theCoordinate.longitude = polyclinics.longtitude;
    theCoordinate.latitude = polyclinics.latitude;

    myAnnotation.pinColor = MKPinAnnotationColorPurple;
    myAnnotation.coordinate = theCoordinate;
    myAnnotation.title = polyclinics.name;
    myAnnotation.subtitle = [NSString stringWithFormat:@"%i",polyclinics.telephone];
    //myAnnotation.annotationsPatients = 

    [_mapView addAnnotation:myAnnotation];
    [_annotation2 addObject:myAnnotation];
}

for(PatientDetails *patientDetails in _listOfPatients){
    MyAnnotation2 * myAnnotation =[[MyAnnotation2 alloc] init];

    CLLocationCoordinate2D theCoordinate;
    theCoordinate.longitude = patientDetails.longitude;
    theCoordinate.latitude = patientDetails.latitude;

    myAnnotation.pinColor = MKPinAnnotationColorGreen;
    myAnnotation.coordinate = theCoordinate;
    myAnnotation.title = patientDetails.nric;
    myAnnotation.subtitle = [NSString stringWithFormat:@"%i",patientDetails.category];

    [_mapView addAnnotation:myAnnotation];
    [_annotation2 addObject:myAnnotation];
}

}

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

NSLog(@"%i", [_annotation2 count]);
    MKPinAnnotationView *pinView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:[annotation title]];

    for(id <MKAnnotation> a in _annotation2){


        if([a isKindOfClass:[MyAnnotation class]]){
        pinView.pinColor = MKPinAnnotationColorPurple;
        }
        else{
            pinView.pinColor = MKPinAnnotationColorGreen;
        }
        pinView.animatesDrop=NO;
        pinView.canShowCallout=YES;
        return [pinView autorelease];



    }
    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-05-23T06:15:18+00:00Added an answer on May 23, 2026 at 6:15 am
    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;
    

    is called every time the MKMapView needs to show a view for an annotation, it passes you that annotation for a reason. So instead of iterating through them and returning only the color for the first one in your array (you need to understand that returning from a function/method doesn’t let the loop iterate more), use the parameter instead.

    Also a good practice is to use

    - (MKAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier;
    

    so the AnnotationViews don’t get created again from scratch, especially memory-wise!

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
    {
        BOOL isGreen = YES;
        if([annotation isKindOfClass:[MyAnnotation class]])
             isGreen = NO;
    
        MKPinAnnotationView *pinView = nil;
    
        if (isGreen) {
            static NSString *greenPin = @"greenPin";
            pinView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:greenPin];
            if (!pinView) {
                 pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:greenPin] autorelease];
                 pinView.pinColor = MKPinAnnotationColorGreen;
                 pinView.animatesDrop = NO;
                 pinView.canShowCallout = YES;
            }
            else
                pinView.annotation = annotation;
    
        }
        else {
            static NSString *purplePin = @"purplePin";
            pinView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:purplePin];
            if (!pinView) {
                 pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:purplePin] autorelease];
                 pinView.pinColor = MKPinAnnotationColorPurple;
                 pinView.animatesDrop = NO;
                 pinView.canShowCallout = YES;
            }
            else
                pinView.annotation = annotation;
        }
    
    
        return pinView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am really posting this out of desperation after searching around a lot for
I have an application that has a UITableView. This UITableView is populated by an
i have this files: //Q2a.h #ifndef Q2A_H #define Q2A_H inline int MyFactorial(int a) {
This is killing me! I'm trying to add the values of four fields together,
Update III: After googling around I've found that this is not an uncommon problem.
I have never hand-coded object creation code for SQL Server and foreign key decleration
(Sorry if this is a dupe) I've just spent a long time trying to
I have an openGL GUI interface and I need to have a popup menu
I have a XIB file with a UITextView, which I'm associating with a UITextView*
For some reason my onPostExecute() is not called after my AsyncTask finishes. My class

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.