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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:36:09+00:00 2026-05-26T08:36:09+00:00

I have an iPhone app with a Core Data database containing a list of

  • 0

I have an iPhone app with a Core Data database containing a list of locations, each with lat/long coordinates. How can I search for say the nearest 10 to my current location?

I’m new to Core Data so my question is really how to do the lookup, I know how to get my current location etc. I believe I need to setup an NSPredicate with a query term but not sure exactly how that should be written.

Thanks,
J

  • 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-26T08:36:10+00:00Added an answer on May 26, 2026 at 8:36 am

    You may try this (reference)

    double M_PI = 3.141592653589793;
    #define d2r (M_PI / 180.0)
    
        double haversine_km(double lat1, double long1, double lat2, double long2) {
            double dlong = (long2 - long1) * d2r;
            double dlat = (lat2 - lat1) * d2r;
            double a = pow(sin(dlat/2.0), 2) + cos(lat1*d2r) * cos(lat2*d2r) * pow(sin(dlong/2.0), 2);
            double c = 2 * atan2(sqrt(a), sqrt(1-a));
            double distance = 6367 * c;
    
            return distance;
        }
    
        - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
            /*Calculate distance of all locations in DB and current location. If diff. between any stop is less than x meters, perform desired operation*/
            NSArray *listLocationsFromDB = [self getLocations]; //Get all locations from DB
            for (Location *location in listLocationsFromDB) {
                double distance = haversine_km(newLocation.coordinate.latitude, newLocation.coordinate.longitude, [location.latitude doubleValue], [location.longitude doubleValue]);
                distance *= 1000;
                if (distance <= 200) {  //200 meters
                    //Your code here
                }
            }   
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Core Data-based iPhone app with a pre-populated read-only database. What protection
I have an iPhone app using Core Data, but I can't seem to figure
In my iPhone Core Data app I have it configured in a master-detail view
I have an iPhone app that has a sqlLite Core Data model that is
I have a Core Data app that will end up being an iPhone/iPad universal
An iPhone app which I am creating generates reports from a Core Data database
I have an iPhone/iPad app which uses Core Data. In my DB I have
I have an iPhone app up on the store which uses core data. Now,
My iPhone app currently uses core data. I want to create an online database
I have an iPhone app with a Core Data object that has a color

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.