+ Reply to Thread
Results 1 to 7 of 7

Finding the distance between two GPS locations

  1. #1
    Registered User
    Join Date
    03-04-2015
    Location
    Manawatu, New Zealand
    MS-Off Ver
    2013
    Posts
    3

    Finding the distance between two GPS locations

    Morning,

    I'm hoping you guys can point out the error I have here? As part of my research I'm including a variable with the distance (in miles) from the capital of my donor country to the capital of every other country in the world. I've been trying to use the Haversine formula, found here: http://andrew.hedges.name/experiments/haversine/ but I can't get it to work in excel.

    Formula:
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
    c = 2 * atan2( sqrt(a), sqrt(1-a) )
    d = R * c (where R is the radius of the Earth 6373 km)

    My Excel:
    a =(SIN(dlat/2)^2+(COS(Capitals[@Latitude])*(COS(lat2)*((SIN(dlon/2))^2))))
    c =2*(ATAN2(SQRT(a), SQRT(1-a)))
    d =R*c

    As a test I've been using

    New Zealand
    Lat:-41.29
    Long: 174.78

    Afghanistan
    Lat: 34.53
    Long: 69.17

    for output I get
    a = 0.332632
    c = 1.912...
    d = 12182.13

    whereas the answer is actually 13650.679. I suspect the issue is to do with degrees to radians but I'm not sure how to incorporate that into the formula?

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Finding the distance between two GPS locations

    Why are you using the radius of the earth in km if you want the distance in miles (3960) ?

    Here's the formula I have in one of my files:

    3960*ACOS(COS(RADIANS(90-C4))*COS(RADIANS(90-E4))+SIN(RADIANS(90-C4))*SIN(RADIANS(90-E4))*COS(RADIANS(D4-F4)))

    where C4 = lat1, D4=long1, E4 = lat2 and F4=long2.

    Hope this helps.

    Pete

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Finding the distance between two GPS locations

    Using your values for New Zealand and Afghanistan, I get 13650.68 km or 8482.14 miles.

    Pete

  4. #4
    Registered User
    Join Date
    03-04-2015
    Location
    Manawatu, New Zealand
    MS-Off Ver
    2013
    Posts
    3

    Re: Finding the distance between two GPS locations

    Hey this works for me, thanks a bunch.

    Primarily the data will be used in miles, but there is some other work for which I need it in km (which I am more comfortable using) so I just got a bit turned around.

  5. #5
    Registered User
    Join Date
    06-02-2014
    Posts
    5

    Re: Finding the distance between two GPS locations

    Is this formula will calculate distance for small distance < 100 mtrs.

  6. #6
    Registered User
    Join Date
    03-04-2015
    Location
    Manawatu, New Zealand
    MS-Off Ver
    2013
    Posts
    3

    Re: Finding the distance between two GPS locations

    I believe that it's accurate to around 0.3% as it's a spherical calculation, whereas the Earth is slightly elliptical. It will tend to overestimate trans-polar distances and underestimate trans-equatorial distances.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Finding the distance between two GPS locations

    Glad to help.

    If that takes care of your original question, please select Thread Tools from the menu above your first post and mark this thread as SOLVED.

    Also, since you are relatively new to the forum, you might like to know that you can directly thank those who have helped you, and leave a comment if you wish to, by clicking on the small "star" icon located in the lower left corner of a post that you have found to be helpful (not just in this thread - for any post that has helped you). This also adds to the reputation of the poster (the small green bars in the poster's profile).

    Pete

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. finding distance from one station to another
    By new1 in forum Excel General
    Replies: 9
    Last Post: 02-05-2015, 09:09 AM
  2. Finding distance between two adresses
    By murti12 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-18-2014, 07:18 AM
  3. Distance Between Two Locations
    By Zan03 in forum Excel General
    Replies: 4
    Last Post: 05-04-2010, 02:40 PM
  4. Locations finding
    By tbobo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-02-2008, 07:16 PM
  5. Finding Point Locations
    By cweaver in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 07-02-2007, 08:58 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1