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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:28:31+00:00 2026-06-06T03:28:31+00:00

I am creating an app that will point a simple arrow in the direction

  • 0

I am creating an app that will point a simple arrow in the direction of a GPS coordinate I have plotted out. So I am talking my current location lat and long, so lat1, lon1 is the current location… then comparing them against a static coordinate of lat and long called lat2, lon2.

I have spent HOURS researching and testing, but I keep on getting the same problem. It’s very aggravating. As soon as I start to drive towards my destination the arrow is all out of whacked when using the iPhone’s built in GPS/compass. It will sometimes show the arrow the complete opposite side of where it needs to be, hanging to the right… pretty much nothing that is solid.

Here is the current code I am running

cpLocLat = 43.026629;

cpLocLon = -78.867188;

Those are float values and the coordinates of where I want to drive to.

float lat1 = self.locManager.location.coordinate.latitude;
float lat2 = cpLocLat;
float lon1 = self.locManager.location.coordinate.longitude;
float lon2 = cpLocLon;

float heading = atan2(sin(lon2 - lon1) * cos(lat2), cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon2 - lon1));

heading = RADIANS_TO_DEGREES(heading);

if (heading < 0) {
    heading = heading + 360;
}

I use this function every time the locationManager didUpdateToLocation delagate is called. Once I have that information, it is used in the locationManager didUpdateHeading delagte with the following:

CGAffineTransform where  = CGAffineTransformMakeRotation(degreesToRadians((degrees - newHeading.magneticHeading)));

[self.compassContainer2 setTransform:where];

and here is the degressToRadians macro

#define degreesToRadians(x) (M_PI * x / 180.0)

So whenever I run this code it is failing epically and is making me go nuts!

BTW – I have used the following URLs for reference

http://www.shawngrimes.me/2011/07/calculating-heading-with-corelocation/

Using Compass to point to actual coordinate location instead of just North

Point to location using compass

  • 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-06T03:28:32+00:00Added an answer on June 6, 2026 at 3:28 am

    To my knowledge, the formula for the initial bearing according to the Haversine formula is:

    θ = atan2( sin(Δlong).cos(lat2),
    cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong) )

    which seems to be exactly what you used. According to the man entry, you might have to use the reverse order of the two arguments to atan2:

    ATAN2(3)                 BSD Library Functions Manual                 ATAN2(3)
    
    NAME
         atan2 -- arc tangent function of two variables
    
    SYNOPSIS
         ....
         float
         atan2f(float y, float x);
    

    So y comes before x. Maybe that is the error.
    Also, make sure that the coordinate deltas (lat2-lat1 etc.) are in radians.

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

Sidebar

Related Questions

I'm creating and app that will rely on a database, and I have all
I am creating an app that will be used to send emails. I don't
I am creating a little app that will let a user read what's in
I am creating an exercise app that will record the weight used and the
I am working on creating a web app that will query event logs on
I'll be creating an app that will start it's life as an iPhone app.
I have this app of mine that contains a section that will allow the
I'm creating a simple Android App, it will be a map with a number
I'm creating an app that will play a song with AVAudioPlayer, and I setup
I'm creating an app that uses CloudApp . I am using TestHarness in order

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.