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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:07:33+00:00 2026-06-06T15:07:33+00:00

I am trying to check if the annotation exists before adding it to array.

  • 0

I am trying to check if the annotation exists before adding it to array.
I can’t figure out why [visibleAnnotations containsObject:annotation] always returns False.

MKMapRect mRect = self.locationView.visibleMapRect;
NSSet *visibleAnnotations =[self.locationView annotationsInMapRect:mRect];
NSLog(@"Annotation in Rect %@",visibleAnnotations);

for(NSArray * obj in JSON){
                coordinates.latitude=[[obj valueForKey:@"Latitude"] doubleValue];
                coordinates.longitude=[[obj valueForKey:@"Longitude"] doubleValue];
                NSString *title=[NSString stringWithFormat:@"%@",[obj valueForKey:@"DeviceId"]];
                MapAnnotation *annotation = [[MapAnnotation alloc] initWithTitle:title andCoordinate:coordinates] ;

                NSLog(@"New Annotation %@",annotation);

                if ([visibleAnnotations containsObject:annotation ]) {
                    //[addPins addObject:annotation];
                    NSLog(@"Contains obj");
                }
                [addPins addObject:annotation];
                [annotation release];
            }

Zoomed to only show 1 annotation.

 Annotation in Rect {(<MapAnnotation: 0x1cd80720>)}
 New Annotation <MapAnnotation: 0x1cd79410>

Thanks

  • 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-06T15:07:34+00:00Added an answer on June 6, 2026 at 3:07 pm

    If you never change the properties of your MapAnnotation instances once they are created and added to the set, you could override the hash and isEqual: methods for that class to get the behavior you’re looking for here.

    NSSet uses those two methods to test objects; if you redefine isEqual: to compare the values contained in the MapAnnontation objects, rather than the identity of the objects themselves, the set will take them to be equal.

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

Sidebar

Related Questions

Can some on help me out here? I am trying check each directory entry
I was trying to check check-boxes using array in jquery using multiple select options
I am trying to check that an address isn't being used before I delete
I'm trying to figure out how to have Spring Security return a UserDetails object
Trying to check and see if a artist exists, if not add or link
I am trying to check if a certain hash element exists. I have two
I am trying to check add the following constraint but Oracle returns the error
im trying to check if a registry key exists and no matter what i
I'm trying to check if a service exists on a remote machine using the
I am trying to check if a file exists in my rails application. I

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.