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

  • Home
  • SEARCH
  • 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 1021901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:22:53+00:00 2026-05-16T11:22:53+00:00

I have a map marker to which I’ve added an event listener. when I

  • 0

I have a map marker to which I’ve added an event listener. when I click on the marker, I can get it to NSLog out a message… yet when I then click on the map, it does the same. I don’t know if this is usual behaviour? In the end, I am trying to get a popup viewcontroller appearing – but that’s been put on hold until this works.

So… I have sub-classed the annotationview which looks like this

- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    if(self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) {
        self.image  = [UIImage imageNamed:@"numberplate.png"];
        self.frame = CGRectMake(0,0,133,40);
        self.centerOffset = CGPointMake(76,0);
        //self.selected = NO;
        self.canShowCallout = NO;
    }
    return self;
}

Then in my main view controller, I have

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

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

    [eventView addObserver:self
                forKeyPath:@"selected"
                   options:NSKeyValueObservingOptionNew
                   context:GMAP_ANNOTATION_SELECTED];

    eventView.annotation = annotation;
    return eventView;
}

So then in my event listener, I have

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context{

    NSString *action = (NSString*)context;
    NSLog(@"action received: %@", context);

    if([action isEqualToString:GMAP_ANNOTATION_SELECTED]){
        NSLog(@"ooh you clicked the annotation!");
    }
}

I also set the GMAP_ANNOTATION_SELECTED as

NSString * const GMAP_MAP_SELECTED =
@”mapselected”;

The output I get when I click the marker is as expected. But when I click the map area, I get the same response! (as if I’d clicked on the map).

Do I need to add some sort of listener to the mkmap to cancel all annotations or something??

  • 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-16T11:22:54+00:00Added an answer on May 16, 2026 at 11:22 am

    You’ll get a notification each time the property “selected” is changed. So you will get this notification when your view is deselected. So, if you have just selected this annotation and then tapped somewhere else to deselect it, you will have received this notification twice.

    BTW, subtle possible bug in your code: if you end up dequeueing this annotation view, you may be registering the observer more than once. You need to make sure you remove the observer when the view is enqueued OR simply register the observer once when the view is created (within the ‘if (eventView == nil)’

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

Sidebar

Related Questions

I have a Map which is to be modified by several threads concurrently. There
I have a map with multiple markers, which I populate via an array. Each
I have a map in which I apply a custom overlay using KMbox overlay
On this page I have a link to a google map which opens in
My sandbox is here: http://9.latest.truxmap.appspot.com/ First click a marker on the map (if there
I have this code which is initated on load // Display the map function
I am working on an android geolocation app. In that I have added marker
I have unsorted map of key value pairs. input = { xa => xavalue,
I have a map defined like this std::map<some_key_type, std::string::iterator> mIteratorMap; And a huge string
I have a map for my game, I have a script that on a

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.