Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Checking my math for distance between 2 points in miles

Hello I am trying to do a calculator of finding the distance between 2 points. Everything works properly. I just want to make sure that my math is correct for the calculations. I will give you 2 coordinates to plug in and tell me if it is right or wrong. Thanks.

Test Coordinates: lat1: 27.95094 lng1: -82.45404

lat2: 27.9659 lng2: -82.8001

Test Results:

21.13 Miles

I just want to check that I am getting the correct calculations from 1 point to the next or if my math is incorrect. Thanks.

function distance(lat1, lng1, lat2, lng2, unit) {
                var radlat1 = Math.PI * lat1/180;
                var radlat2 = Math.PI * lat2/180;
                var theta = lng1-lng2;
                var radtheta = Math.PI * theta/180;
                var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
                if (dist > 1) {
                    dist = 1;
                }
                dist = Math.acos(dist);
                dist = dist * 180/Math.PI;
                dist = dist * 60 * 1.1515;
                if (unit=='miles') { dist = (dist * 0.8684) * 1.15077945 }
                return dist;
            }

       travel = distance(lat1, lng1, results.features[0].center[1], results.features[0].center[0], 'miles');

       travel = parseInt(travel * 100)/100;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Yes, you seem to have implemented the Haversine formula correctly (https://en.wikipedia.org/wiki/Haversine_formula)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!