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

  • Home
  • SEARCH
  • 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 912065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:19:04+00:00 2026-05-15T17:19:04+00:00

Does anyone have an algorithm to determine the direction from one lat/lon to another

  • 0

Does anyone have an algorithm to determine the direction from one lat/lon to another (pseudo-code):

CalculateHeading( lat1, lon1, lat2, long2 ) returns string heading

Where heading is e.g. NW, SW, E, etc.

Basically, I have two points on a map and I want to get a general idea of the direction taking into account that 50 miles East and one mile North is simply East and not Northeast.

  • 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-15T17:19:05+00:00Added an answer on May 15, 2026 at 5:19 pm

    This site has the basic algorithm:

    // in javascript, not hard to translate...
    var y = Math.sin(dLon) * Math.cos(lat2);
    var x = Math.cos(lat1)*Math.sin(lat2) -
            Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
    var brng = Math.atan2(y, x).toDeg();
    

    UPDATED: See here for complete algorith Mapping Math and Javascript

    That’ll give you a number between 0 and 360 then it’s just a matter of having a simple lookup:

    var bearings = ["NE", "E", "SE", "S", "SW", "W", "NW", "N"];
    
    var index = brng - 22.5;
    if (index < 0)
        index += 360;
    index = parseInt(index / 45);
    
    return(bearings[index]);
    

    It’s important to note that your bearing actually changes as you move around the earth. The algorithm above shows you initial bearing, but if you’re traveling a long distance, your bearing to be significantly different when you reach the destination (if you’re only traveling a short distance [< a few hundred kms] then it probably won’t change enough to be a concern).

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

Sidebar

Related Questions

Does anyone have a recommended pseudo-algorithm for, given a string containing an address: Break
Does anyone have a straightforward description of the algorithm for constructing the union of
I have a sine wave whose parameters I can determine (they are user-input). It's
I am currently working on reimplementing some algorithm written in Java in Python. One
I have user input that consists of a drawn rectangle (freestyle). Now this drawn
Lets suppose I am trying to analyze an algorithm and all I can do
This question is more logic than programming at the moment.. once I understand what
I'm working on a cluster analysis program that takes a set of points S
I am working on a piece of software which generated a polygon mesh to
I routinely graph time series data in Excel, and I find the default Excel

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.