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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:36:59+00:00 2026-06-15T20:36:59+00:00

I need to find the angle between the north and a point in a

  • 0

I need to find the angle between the north and a point in a map (21.4167, -39.8167).

here is my code

double MECCA_LONGITUDE = 21.4167;
double MECCA_LATITUDE = -39.8167;

-(void) getAngle :(float) phoneAngle: (float) lon:(float) lat
{

 float ad = atan (sin (lon - MECCA_LATITUDE) /  ( (cos (lat)) * (tan (MECCA_LATITUDE)) ) - ( (sin (lat)) * (cos (lon - MECCA_LONGITUDE)) ));

NSLog(@"###### %f", CC_RADIANS_TO_DEGREES(ad));
}

I’m still not getting the correct answer. Any tips would be appreciated. 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-15T20:37:00+00:00Added an answer on June 15, 2026 at 8:37 pm

    Your principle problem is that sin() and cos() take their arguments in radians, and you are passing degrees (you also have the longitude and latitude of Mecca interchanged).

    Try:

    double MECCA_LATITUDE = 21.4167;
    double MECCA_LONGITUDE = 39.8167;
    
    double r_delta_lon = CC_DEGREES_TO_RADIANS(MECCA_LONGITUDE - lon);
    double r_lat2 = CC_DEGREES_TO_RADIANS(MECCA_LATITUDE);
    double r_lon1 = CC_DEGREES_TO_RADIANS(lon);
    double r_lat1 = CC_DEGREES_TO_RADIANS(lat);
    
    double ad = atan2(sin(r_delta_lon) * cos(r_lat2),
        cos(r_lat1) * sin(r_lat2) - sin(r_lat1) * cos(r_lat2) * cos(r_delta_lon));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to find the coordinates of the second point. I know the angle
I need to find out the value passed into an indexer. My code (c#)
I'm in desperate need to constantly find the heading angel between my device/location and
Im trying to find out the angle (in degrees) between two 2D vectors. I
How can I find the Angle of a line between two points in actionscript
I need to find a point where a line (its origin is ellipse' center)
Let me just start with the code. - (NSPoint*) pointFromPoint:(NSPoint*)point withDistance:(float)distance towardAngle:(float)angle; { float
Need to find the timestamp for the first minute of the first day of
I need to find a flexible solution for access control in PHP. In the
i need to find out automationid for key board values? how to send keystrokes

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.