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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:16:51+00:00 2026-05-16T15:16:51+00:00

I’ve just found a strange issue with my sub classed mkannotationview. When I add

  • 0

I’ve just found a strange issue with my sub classed mkannotationview.

When I add the first 5 markers, they all work perfectly. In the mkannotationview sub class, I NSLog a message which I see 5 times. However, when I remove ALL the markers and redraw them – using all the same methods, I see the NSLog only once.

It’s like the map is reusing existing annotationviews? Is there a way to force it to use new ones each time?

[UPDATE with code]

So the reason I cannot reuse (and this may or may not be the problem) is that I am creating unique markers with a label. The label on the marker contains a reference to the individual marker (consider it like a product ID)

So… in ProductPlot.h

@interface ProductPlot : NSObject <MKAnnotation> {
    NSString *productID;
    float latitude;
    float longitude;
}
@property (nonatomic, copy) NSString *productID;

and ProductPlot.m

@implementation ProductPlot
@synthesize productID;

- (CLLocationCoordinate2D)coordinate {
    CLLocationCoordinate2D coord = {self.latitude, self.longitude};
    return coord;
}

- (NSString *) productID {
    return productID;
}

then I have the annotation view sub classed as ProductPlotView.h

@interface ProductPlotView : MKAnnotationView {
ProductPlot *product;
}

and in ProductPlotView.m

@implementation ProductPlotView

- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    if(self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) {

        product = (ProductPlot *)annotation;
        UILabel *plate2 = [[[UILabel alloc] init] autorelease];
        plate2.text = product.productID;
        plate2.frame = CGRectMake(35, 4, 100, 30);
        plate2.backgroundColor = [UIColor clearColor]; //]clearColor];
        [plate2 setFont: [UIFont fontWithName: @"myFont" size: plate2.font.pointSize]];

        [self addSubview:plate2];
    }
    self.frame = CGRectMake(0,0,133,40);

    return self;
}

So then in my code, I plot the points using

- (void)plotPoint: (int) y latitude: (double) lat longitude: (double) lng productID: (NSString *) pID {

    ProductPlot *newAnnotation = [[ProductPlot alloc] init];
    newAnnotation.latitude = lat;
    newAnnotation.longitude = lng;
    newAnnotation.productID = pID;
    [mapView addAnnotation:newAnnotation];

    [newAnnotation release];

}

I also have the code to handle the annotations.

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



    ProductPlotView *eventView = (ProductPlotView *)[lmapView
                                    dequeueReusableAnnotationViewWithIdentifier:@"eventview"];
    if(eventView == nil) {
        eventView = [[[VehicleViewInfo alloc] initWithAnnotation:annotation
                                                     reuseIdentifier:@"eventview"]
                     autorelease];
    }

    eventView.annotation = annotation;
    return eventView;
}

So… the above will take the productID and place it on a label which is the map marker. This seems to work perfectly on the FIRST plot instance, but if I remove the markers (using [mapView removeAnnotations:mapView.annotations];) then call this function again, it draws the points OK, but the product IDs are not correct. It appears to draw them at random.

NOTE: the code above has had a few
parts removed, so there may be typos

Thanks for any info.

  • 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-16T15:16:52+00:00Added an answer on May 16, 2026 at 3:16 pm

    To answer my own question, I added MKAnnotationView* annotationView = nil; to the top of my - (MKAnnotationView *)mapView:(MKMapView *)lmapView viewForAnnotation:(id <MKAnnotation>)annotation code.

    Now it seems to be working perfectly. I’d still be keen to see if others think that this is the correct way to do this?

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.