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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:09:52+00:00 2026-05-28T04:09:52+00:00

I am trying to do the great circle distance calculation . As you should

  • 0

I am trying to do the great circle distance calculation. As you should be able to glean, the Location class has the properties listed in the calculation.

- (NSNumber *)greatCircleDistanceFrom:(Location *)other
{
    // Unpack all the NSNumbers into doubles so we can manipulate them
    double selfCosRadLat = [self.cosRadLat doubleValue];
    double otherCosRadLat = [other.cosRadLat doubleValue];
    double selfRadLng = [self.radLng doubleValue];
    double otherRadLng = [other.radLng doubleValue];
    double selfSinRadLat = [self.sinRadLat doubleValue];
    double otherSinRadLat = [other.sinRadLat doubleValue];

    // Multiplying by 3959 calculates the distance in miles.
    double d = acos(selfCosRadLat
                    * otherCosRadLat
                    * cos(selfRadLng - otherRadLng)
                    + selfSinRadLat
                    * otherSinRadLat
                    ) * 3959.0;

    return [NSNumber numberWithDouble:d];
}

Half the time I run my unit test, I get the right value. The other half, I get 6218.78265778.

  • 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-28T04:09:53+00:00Added an answer on May 28, 2026 at 4:09 am

    Make sure that your incoming Location value isn’t nil or 0,0. It seems like the reason you’d get a constant like that is because it is doing the math as if it were at 0°,0°. Are you 6218 miles from approximately west Africa? If so, your function is working great, but the method calling it isn’t providing real values some of the time.

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

Sidebar

Related Questions

I'm trying to make a utility httpClient class My code works great the first
I'm having a great deal of difficulty trying to achieve something that should be
Would be great to get some direction re trying to use sqlite for my
I'm trying to convert some code that worked great in VB, but I can't
I'm trying to model my tests after the great work that the Thougtbot guys
I'm having a great deal of difficulty trying to figure out the logic behind
I'm trying to sort any array with array_multisort() and everything is working great. However,
I'm trying to compile this function from Learn You a Haskell for Great Good
I received some great help on joining a table to itself and am trying
So I'm trying to adapt this Dropdown menu on Joomla the styles work great

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.