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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:10:10+00:00 2026-05-23T12:10:10+00:00

I have an Array of MKAnnotation objects called arrAnnotations . I want to pick

  • 0

I have an Array of MKAnnotation objects called arrAnnotations. I want to pick out one of the annotations with the same coordinate as the one stored in a CLLocation object called “newLocation”.

I’m trying to use a NSPredicate, but it doesn’t work.

NSPredicate *predicate = [NSPredicate  predicateWithFormat:@"(SELF.coordinate == %f)", newLocation.coordinate];
NSArray* filteredArray = [arrAnnotations filteredArrayUsingPredicate:predicate];
[self.mapView selectAnnotation:[filteredArray objectAtIndex:0] animated:YES];

The filteredArray always contains zero objects.

I have also tried the following, which do not work either

NSPredicate *predicate = [NSPredicate  predicateWithFormat:@"(coordinate == %f)", newLocation.coordinate];

and

NSPredicate *predicate = [NSPredicate  predicateWithFormat:@"(coordinate > 0)"];

and

NSPredicate *predicate = [NSPredicate  predicateWithFormat:@"(coordinate.latitude == %f)", newLocation.coordinate.latitude];

The last two crash the app, the third one with an NSInvalidArgumentException for [NSConcreteValue compare:] and the fourth, because latitude is not key-value-coding-compliant (I assume this is because coordinate is just a c-struct and not an NSObject?).

How can I make this work with NSPredicate?
Can anyone give me a link to a document that shows how Predicates work under the hood?
I don’t understand what they actually do, even though I have read and understood most of Apple’s Predicate Programming Guide.
Is searching a huge array with predicates more efficient than just looping through it with a for…in construct? If yes/no, why?

  • 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-23T12:10:11+00:00Added an answer on May 23, 2026 at 12:10 pm

    MKAnnotation protocol’s coordinate property is a CLLocationCoordinate2D struct, thus it is not allowed in NSPredicate format syntax according to the Predicate Format String Syntax

    You could use NSPredicate predicateWithBlock: instead to accomplish what you are trying to do, but you have be careful with CLLocationCoordinate2D and how to compare it for equality.

    CLLocationCoordinate2D‘s latitude and longitude property are CLLocationDegrees data type, which is a double by definition.

    With a quick search you can find several examples of problems you would face when comparing floating point values for equality. Some good examples can be found here, here and here.

    Given all that, I believe that using code bellow for your predicate might solve your problem.

    NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
    
        id<MKAnnotation> annotation = evaluatedObject;
    
        if (fabsf([annotation coordinate].latitude - [newLocation coordinate].latitude) < 0.000001 
                && fabsf([annotation coordinate].longitude - [newLocation coordinate].longitude) < 0.000001) {
            return YES;
        } else {
            return NO;
        }
    
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of hashes, and I want the unique values out of
I have array of objects. I want to write method wich i will use
I have array with colors as its objects. I want to create an image
I have array of objects with created images (Object.Image), i want to show images
I have array of objects MyClass MyArr[10]; In method of one element of array
I have an array list called str, i want to see how many elements
I have an array list called str, i want to see the elements inside
I have an array in Perl: my @my_array = (one,two,three,two,three); How do I remove
I have an array I've created in JavaScript. The end result comes out to
I have an array of shorts (short[]) that I need to write out to

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.