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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:33:47+00:00 2026-06-15T22:33:47+00:00

I have used annotation map and used more than one image for the pins

  • 0

I have used annotation map and used more than one image for the pins but whenever I zoom in or zoom out, it changes all the pins to one image.

I get the locations from a web service and to recognise them, I used a string (CustAttr) as “T” or “P”.

The problem is the last call from a web service makes the CustAttr = T and when I zoom in or zoom out, it calls the mapView viewForAnnotation method and draws them all as T and all the P pins are changed.

Here is the code for the method :

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

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

}
static NSString* AnnotationIndentifer = @"AnnotationIdentifier";



if ([custAttr isEqualToString:@"T"]) // ATMs
{
    MKAnnotationView* pinView;
    pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIndentifer];

    MapAnnotation* mapAnnotation = annotation;
    pinView.canShowCallout = YES;

    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
    pinView.rightCalloutAccessoryView = rightButton;

    if (mapAnnotation.isClosest) {
        pinView.image = [UIImage imageNamed:@"Closest_ATM.png"];

    }
    if (mapAnnotation.isOffline) {
        pinView.image = [UIImage imageNamed:@"Offline_ATM.png"];
    }
    pinView.annotation = annotation;
    return pinView;        

}else if ([custAttr isEqualToString:@"P"]) // POIs
{
    MKAnnotationView* pinView;
    pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIndentifer];

    pinView.canShowCallout = YES;
    pinView.image = [UIImage imageNamed:@"Location_POI.png"];
    pinView.annotation = annotation;
    return pinView;
}

return nil;
}

How can I resolve this issue? Is there a way that I can prevent it from calling this method when zooming in/out or is there another way to let it draw them again as in the same image?

  • 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-15T22:33:48+00:00Added an answer on June 15, 2026 at 10:33 pm

    The custAttr variable (which you are setting outside the delegate method) will not always be in sync with the annotation that the viewForAnnotation delegate method is called for.

    The delegate method is not necessarily called right after addAnnotation or addAnnotations and can be called multiple times for each annotation if the map needs to display the annotation view again after a zoom or pan.

    When it gets called again for the same annotation, the custAttr variable no longer matches up.

    You need to add a custAttr property (I suggest using a different name) to your MapAnnotation class and set it when creating the annotation (before calling addAnnotation).

    For example:

    MapAnnotation *ann = [[MapAnnotation alloc] init];
    ann.coordinate = ...
    ann.title = ...
    ann.subtitle = ...
    ann.custAttr = custAttr; // <-- copy to the annotation object itself
    [mapView addAnnotation:ann];
    

    Then, in viewForAnnotation, read the custAttr property from the annotation parameter (after casting it to MapAnnotation *) instead of referencing the externally declared custAttr.

    You may want to use a different name for the custAttr property in MapAnnotation to avoid confusion.

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

Sidebar

Related Questions

I have a more complicated issue (than question 'Java map with values limited by
I have used the method described here to localize my data annotation messages and
If I have a parametrized annotation which is used on a field, can the
I have used the silverlight control in CRM 2011.It also published on form but
I have used a plugin that uses prototype js, it's working fine but the
I have used NSSets many times in my apps, but I have never created
I have used below getter method level XmlElement annotation for generating xsd from Java
In my application i have used mapview. On particular place i can put annotation.
I have been used to generating entity classes from database in .net. But recently
I have write following code to show bar plot annotation. Annotations are shown but

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.