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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:01:50+00:00 2026-06-07T13:01:50+00:00

I added MKAnnotation in my mapview using the following code. Flag *flag = [[Flag

  • 0

I added MKAnnotation in my mapview using the following code.

Flag *flag = [[Flag alloc] init]; 
flag.title = @"Golf Course";
flag.subtitle = @"Green"; 
flag.coordinate =CLLocationCoordinate2DMake(28.457394,77.108667);
[mapView addAnnotation:flag];

and am setting image like

 -(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
 (id <MKAnnotation>)annotation 
 {
   if(([annotation isKindOfClass:[Flag class]])) 
   {
      MKPinAnnotationView *pinView = nil; 
      if(annotation != mapView.userLocation) 
      {
        static NSString *defaultPinID = @"PinId1";
        pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:@"pin1"] autorelease];

        //pinView= [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin1"];

        pinView.canShowCallout = YES;
               pinView.draggable = YES;
        [pinView setImage:[UIImage imageNamed:@"flag2.png"]];

     } 
     else 
     {
        [mapView.userLocation setTitle:@"I am here"];
     }

   }
    return pinView;
 }

but am not getting the image for MKAnnoation.What is wrong am doing?Please help me.

  • 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-07T13:01:51+00:00Added an answer on June 7, 2026 at 1:01 pm

    I have the same issue. Now using the working version as given below.

    - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
    {
        if ([annotation isKindOfClass:[MKUserLocation class]])
            return nil;
    
        if ([annotation isKindOfClass:[Annotation class]])
        {
            static NSString* SFAnnotationIdentifier = @"SFAnnotationIdentifier";
            MKPinAnnotationView* pinView =
            (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:SFAnnotationIdentifier];
            if (!pinView)
            {
                MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
                                                                                 reuseIdentifier:SFAnnotationIdentifier] autorelease];
                annotationView.canShowCallout = YES;
    
                UIImage *flagImage = [UIImage imageNamed:@"map_pin.png"];
    
                CGRect resizeRect;
    
                resizeRect.size = flagImage.size;
                CGSize maxSize = CGRectInset(self.view.bounds,
                                             10.5,
                                             10.5).size;
                maxSize.height -= self.navigationController.navigationBar.frame.size.height + 40.0;
                if (resizeRect.size.width > maxSize.width)
                    resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
                if (resizeRect.size.height > maxSize.height)
                    resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);
    
                resizeRect.origin = (CGPoint){0.0f, 0.0f};
                UIGraphicsBeginImageContext(resizeRect.size);
                [flagImage drawInRect:resizeRect];
                UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
                UIGraphicsEndImageContext();
    
                annotationView.image = resizedImage;
                annotationView.opaque = NO;
    
                UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    
                Annotation *annoterObject = (Annotation *) annotation;
    
                rightButton.tag = annoterObject.annoteCount;
    
                [rightButton addTarget:self
                                action:@selector(showDetails:)
                      forControlEvents:UIControlEventTouchUpInside];
                annotationView.rightCalloutAccessoryView = rightButton;
    
                return annotationView;
            }
            else
            {
                pinView.annotation = annotation;
            }
            return pinView;
        }
    
        return nil;
    
    }
    

    This is the working code.

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

Sidebar

Related Questions

Added this code NSDateFormatter *df = [[NSDateFormatter alloc]init]; NSString *entry = @March 28, 2012;
I added the following code segment to my project to force the JScrollPane automatically
I added to my system-wide /etc/security/limits.conf the following two rows: * soft rtprio 55
I added this part of the code in my onCreate() method and it crashes
I added this code to the head but when I try to post something
I am using MKMapView and have added a number of annotation pins to the
EDIT: Added the NSRunLoop from my code, as mentioned by Deepak below. This was
I added a MKAnnotation delegate handler class into a MKMapView like this. MapAnnotation *anAnnotation
ADDED: This question is now, I believe, subsumed by this one: Using GNU Screen
I have code: if (self.annotations) [self.mapView addAnnotations:self.mapView.annotations]; NSLog(@mapView: %@, anos:%@,self.mapView,self.mapView.annotations); And I get the

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.