I've been looking for this one for ages, and the one I created based on an equation I found a little while ago didn't work too well :(

#### Investigation

Calculate distance, bearing and more between two Latitude/Longitude points shows lots of equations in math, and implemented in JavaScript. Chris Veness's page also contains an Excel formula of the ‘Haversine’ equation (actually, using the "spherical law of cosines") for distances between points in kilometres:

=ACOS(SIN(Lat1)*SIN(Lat2) +COS(Lat1)*COS(Lat2)*COS(Lon2-Lon1)) *6371

But it wasn't working, because my GPS points (Lat/Lon) were in decimal degrees, not radians. So I used the formula I found at Latitude And Longitude In Excel (under the "Great Circle Distances" section) by Chip Pearson:

=RadiusEarth*ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2)))

where Chip gives RadiusEarth as 6378.135 kilometres. This didn't match up with distances I had when calculated from other systems. But Chris's page has:

R = earth’s radius (mean radius = 6,371km)

Digging deeper, I found Chris's Vincenty formula for distance between two Latitude/Longitude points page which includes a table on different datum models (treating Earth as an ellipsoid), it shows WGS-84 & GRS-80 having the greatest radius on an ellipsoid as 6378.135km & the smallest as 6356.752km.

So Chip was using the maximum radius of the Earth, not the mean radius like Chris (I'm not sure where Chris gets the mean radius from). Substituting Chris's R for RadiusEarth in Chip's formula gives:

#### Solution

=ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2))) *6371

and my final version that uses Excel cell references is:

=ACOS(COS(RADIANS(90-A2)) *COS(RADIANS(90-A3)) +SIN(RADIANS(90-A2)) *SIN(RADIANS(90-A3)) *COS(RADIANS(B2-B3))) *6371

PS. To calculate distances in miles, substitute R (6371) with 3958.756 (and for nautical miles, use 3440.065).

You are the man. After much searching, your post gave me just the Excel formula I needed, with the correct distances (as measured at that moveable-type site)

ReplyDeleteI'm trying to visit every Larosas, Busken, Graeters and Skyline in Cincinnati in one day, and was trying to figure out distances

dan.

www.everywhatever.com

Simply... Thank you

ReplyDeleteThanks so much, this is exactly what I was looking for.

ReplyDeleteBless you.

ReplyDeleteThank you- this, plus the batch calculator at www.batchgeocoder.com make for a powerful combination... Saved me loads of research!!!

ReplyDeleteThank you!!!

ReplyDeleteYou made my day!

ReplyDeleteThanks a lot!

From a happy Norwegian

Thanks so much, it saved me hours.

ReplyDeleteI'm setting up mini-conferences around the country, and your formula made it easy to convert a database of zip code lat/lon figures into distances. Now I can sort cities instantly by distance from a point. Thanks! Mark Lee

ReplyDeleteImpressive ! Thanks a lot, I needed 15 minutes to tweak it the way I need instead of hours of copy/paste ! Thanks :))

ReplyDeleteAmazing! just what I was looking for!

ReplyDeleteThis is what I'm looking for, thanks.

ReplyDeleteDistance between two points with curvature of earth accounted for.

Thanks very much.

Thanks a million!!!

ReplyDeleteThanks a lot! You really really made my day. I was constructing a distance variable between households and health facility to use it in a service use prediction in stata. I spent time looking for a command i stata (i don't have a GIS soft)...the I found your formula). Thanks a million!

ReplyDeleteAbsolutely wonderful!

ReplyDeleteAbsolutely wonderful

ReplyDeleteExcellent, just excellent. Thanks very, very much.

ReplyDeletePerfectamundo. I downloaded some Lat/Long data by zip code and imported it into my SQL database. I then tweaked your formula to be able to use it in Crystal Reports.

ReplyDeletethat is so so frickin cool. thank you

ReplyDeleteThis is the Bomb!!!

ReplyDeleteYou've saved me so much effort - thanks!

ReplyDeleteThank you..Very Simply

ReplyDeleteAlvaro...From Brasil/ São Paulo.

U be 'da man!!!

ReplyDeleteYou are a life saver!

ReplyDeletesimply amazing..thx

ReplyDeleteThank you very much. This is excellent!! Saved so much time. God bless you

ReplyDeleteYou are a life saver.

ReplyDeleteFinally found what I need.. thank you so much!!!

ReplyDeleteOMG, you are the master of the masterss.. it save me a lot of time and extra points with my boss.

ReplyDeleteThis is AWESOME... though i'd love to see how to calculate travel-distance between 2 zip codes/2 lat/longitudes

ReplyDeleteThanks a lot. Saved a lot of time.

ReplyDeleteAwesome ! Great formula and even better description.

ReplyDeleteYep. thanks!

ReplyDeleteThanks for creating a very useful tool! You made my day!

ReplyDeleteI cannot believe how simple you made this look! i sent hours looking at other formulas and when I tried to convert it it was always the wrong answer

ReplyDeleteIt nice that the internet is used for such great resources and that people like are willing to share their wonderful skills

I cannot believe how simple you made this look! i sent hours looking at other formulas and when I tried to convert it it was always the wrong answer

ReplyDeleteIt nice that the internet is used for such great resources and that people like are willing to share their wonderful skills

amazing!

ReplyDeleteYou just saved me doing this manually 260 times. I owe you a MASSIVE beer.

ReplyDeletethis is great-can it be tweaked into Crystal?

ReplyDeleteThanks for sharing this formula! There is just no way I could have figured this out on my own.

ReplyDeleteThis is great. But how do I use it in Crystal?

ReplyDeleteFirst Thanks in 2010. Thanks!

ReplyDeleteHi,

ReplyDeleteThank you for making this easy in excel,but how do you do it in crystal report? Please help.

Thanks.

Thanks a lot. Saved loads of effort

ReplyDeleteFantastic! I am involved in tagging butterflies and was just settling down for a few hours reading to figure out how to do this when I found your answer presented on a silver platter!

ReplyDeleteAwesom!!!

ReplyDelete... and that's why we love the web. Sharing knowledge.

Thank you. You saved me so SO much work.

ReplyDeleteBrilliant...simply brilliant...

ReplyDeleteAwesome

ReplyDeleteYou need to be kissed.

ReplyDeleteI spent 2hrs on this yesterday and failed. With your help I spent 5 minutes today and it worked a treat. Many thanks!

ReplyDeleteJust wonderful! Thanks so much.

ReplyDeleteThis helped me set up a database which calculated the closest branch to every telephone exchange in the country.

kick-ass man.

ReplyDeleteI was getting no where with co-ordinates in degrees, excel and the haversine formula until i found your page, after which my quest was complete. Many thanks.

ReplyDeleteThree years later and you're still being thanked! I have to thank you, too! This is incredible!!

ReplyDeleteWow, I am very much in your debt. I tag rockfish and this task of calculing their movement was a mountain of a task. You have made it easy. Thank you very much.

ReplyDeleteDitto what everyone else has ever said about your good character, name, intellect, the cut of your jib, etc, etc. THANK YOU!!!

ReplyDeleteAmazaing work.... Hats off mate

ReplyDeleteAmazing work.... Hats off mate

ReplyDeleteFinally. Been combing the internet for ages looking for something like this. I couldn't get any of the other formulas I tried to work

ReplyDeleteThank you so much

Really great stuff! I did a lot of investigation with poor results before finding this. A big thanks for the knowledge and sharing it!!!

ReplyDeleteThank you for posting this little piece of genius...

ReplyDeleteMarvellous....

ReplyDeleteOf course.. I now want to move to the next level... :)

My next search, and indeed work myself, is to try to get distances to travel by road, and not just as the crow flies.

I spent HOURS (2 working days) on searching for other formulas that wouldn't work. Yours worked in 2 minutes and saved the day.

ReplyDeleteThis IS the best. Thanks a TON!!!

Perfect mate, cheers. Will vote up this result in the googles.

ReplyDeleteAWERSOME. Saved me a bunch of time to have this already done for me. Thank you!

ReplyDeleteBy the way, since the equations are unit-neutral, you can easily come up with separate distance tables in Miles and Kilometers by changing the value of the Radius from one to the other.

ReplyDeleteamazing!

ReplyDeletepleas expalin what is in the cells A2, A3, B2 and B3.

ReplyDeleteThanks Anthony fba@fbatm.biz

I should have read more. I now understand what A2 A3 B2 and B3 are and it works a treat. Please ignore mt query

ReplyDeleteI love you, Im totally i love with you ;-) Thanks

ReplyDeleteSpent hours trying to make sense of other sites. Found yours, tweaked and had it doing exactly what I needed in minutes!

ReplyDeleteThank you!

Thanks a lot.

ReplyDeleteThis is great. Is there a version that calculates bearing?

ReplyDeleteThanks a lot! Any chance also for the formula to determine the direction/bearing/azimuth from Pt A to Pt B ?

ReplyDeleteThanks a billion!

ReplyDeleteGood work! Many thanks from Wales!

ReplyDeleteThis worked great! Thanks from Ontario!

ReplyDeletethankyou thankyou....!

ReplyDelete(to add to the million other thankyous on this comment page)

ha ha and I'm also from Wales like the guy above...

these Welsh fellas stick together! What are the chances of finding them like this???

Thanks Man. "CHOKRAN" :)

ReplyDeleteThanks - you've made a long and complicated job simple. Brilliant.

ReplyDeleteThanks from sunny Milton Keynes. Saved me a load of time

ReplyDeleteseriously, you are the man!!

ReplyDelete

ReplyDeleteExcellent!Thank you very much indeed for making it available to the rest of us.

AWESOME!!! I have spent hours trying to tweak the formula to work in Excel. Your post made it "copy/paste"! Thanks!

ReplyDeleteThank you so much, this is exactly what i needed

ReplyDeleteConsider me the second happy Norwegian (at least) you've helped out!

ReplyDeleteThank you. I needede to calculate about 1000 flights for my company's carbon footprint. Used a simpler formula that was quite good but slightly inaccurate, did for example return different results when switching the destinations around. Then I found your solution that does the job presisely and was also easy to put into VBA code. After recalculating the 1000 flights the difference was only 0,001% or 90 kg CO2 !! Whatever, always good to have the best methodology in use ! Will certainly look for more tips & tricks on your blog !

ReplyDeleteThank you, wish I had found your site before all the other I looked up first !

ReplyDeleteAnother happy Norwegian..

you are heaven-sent! :) thanks man.

ReplyDeleteThank you very much. By combining your formula and http://www.excelforum.com/excel-programming/537429-closest-neighbour-coordinates.html for coordinate lookup, I was able to do reverse geo coding withing excel. Great job.

ReplyDeleteBrilliant ... now I can easily compute the distance between the Volvo yachts racing around the world!

ReplyDeleteits coolest investigation!, but i just want know how about calculate bearing or azimuth?

ReplyDeletegreat regard :)

engkin

eloknegerikuindonesia

Amazing. I applaud your hard-work and know how as im sure you dedicated a lot of time and energy to perfecting the fomrula. Comparing the distance from Toronto-Denver against geobytes, the formula was accurate within 3.75 miles; 99.8% accurate! Again, amazing. Endless thanks.

ReplyDeleteGenius. Thank you.

ReplyDeleteI looked at over 50 websites on this topic today - and this is the only one that was clear and made sense, thanks!

ReplyDeleteAwesome...

ReplyDeletethank you very much. I've been racking my brain on this all day.

ReplyDeleteyou are a genius among men.

From a smallish charity in Australia: CHEER'S MATE!!

ReplyDeleteThanks for posting this blog .This was so much helpful and was time consuming for mines to calculate the question using your tips .

ReplyDeleteThanks!... This formula gives distances in km?..

ReplyDeleteThanks brother! This is exactly what I was looking for!

ReplyDeleteThanks so so so so much buddy!! You are the man!!! You saved like a million person hours ;)

ReplyDeleteGod bless you

Excellent work and very well presented! You are a credit to your species.

ReplyDeleteThanks. I was going to have to get on Google Earth and use the ruler tool to calculate distances from a central point to a number of weather stations that did have reported lat-long info. Your equation saved me a bunch of time.

ReplyDeleteHow would I reference your work in a paper citation?

Thanks again,

Joe H

Thanks Mate....appreciate your generosity.

ReplyDeleteFantastic, works a treat. Thank you.

ReplyDeleteThank you so much. supper ...

ReplyDeleteWow thank you man. I compares the results to google maps and its within the same proximities. Thank you thank you.

ReplyDeleteDamn, I keep getting the #NUM error and can't figure out what's wrong...

ReplyDeleteThank you!

ReplyDeleteI copied it, pasted it, substituted my cell references for the lat long names, and I was done! It was too easy.

ReplyDeleteThanks!

Steve

Thanks a lot, appreciate it very much :)

ReplyDeleteSuresh

Thanks a lot, it helped me.

ReplyDelete-suresh

I'm pretty sure ppl will thank u 4ever, but I couldn't just use ur info and leave! so here is my THANK YOU as well!

ReplyDeleteTHANKS!!!

ReplyDeleteGreat! Thank you very much!

ReplyDeleteAwesome! I needed to get to feet but had to start somewhere! Just to continue from km to ft take result through =DistKm*3280.8

ReplyDeleteThank you!

ReplyDeleteThank you!

ReplyDeleteHolly ship! you made my day!

ReplyDeleteThank you, thank you, thank you, thank you.

ReplyDeleteLike the others have said, you just saved me a ton of time (that I didn't have).

Cheers from Germany!

This is great - exactly what I was looking for.

ReplyDeleteJust wondering if anyone has been able to build a solution that can take a few hundred points and cluster them based on certain criteria example within 10km of each other?

thank you for your sharing.

ReplyDeleteI searched for this solution for YEARS.......almost no one has ever put this out to where the average non-mathematician guy can obtain and use it. Thank You.

ReplyDeleteThis kind of math is DIFFICULT and not apparent to mere mortals.

Dude, this is awesome. Saved $59 purchase...

ReplyDeleteThank you!!

ReplyDeleteStill useful in 2013. Saved lots of time for me too. Thanks from the UK.

ReplyDeleteFirst of all, Many thanks for sharing this information. I am evaluating a product and I wanted to make sure that the samples are taken in a proper distances..... You saved my time ..I Can do it now ...

ReplyDeleteThanks from Canada :)

great help ! thanks a lot!!!

ReplyDeleteVery glad I came across this solution. Had not caught the mean vs max radius throwing off my calculations. Thanks!

ReplyDeleteYou did a great job at making this post very detailed. I want to say thank you! You even supplied the miles and nautical miles needed!

ReplyDeleteThank you so so much! This has helped my work so so much!!

ReplyDeleteC

thank you!! just what i needed to demonstrate to a client, before we implement it in code.

ReplyDeleteon the first search result.

live long and prosper!829

Mate, you are awesome. I was tearing my hair out trying to make that atan2 thing work and here it is: one formula, in Excel.

ReplyDeleteThe Gods smile on you.

I have a distance calculator but it calc's "nearest" based on sets of l/l inputs so this one did the trick since I needed point to point calculator. Very nice, very easy. As others have said, still relavant in '13.

ReplyDeletethank you so much! i'm so glad God brought me to this!

ReplyDeleteThanks for your formula

ReplyDeleteGOD BLESS YOU, GOOD MAN!!!!!

ReplyDeleteIt works very well,

ReplyDeleteta.

Thanks a lot for taking the time to create this page, you've saved myself, and clearly a lot of other people, a huge amount of time and effort.

ReplyDeleteAppreciative from South Africa.

woah! Thats so cool!

ReplyDeleteThanks so much!

Party on Wayne!!! Thank you!

ReplyDeleteWow! You just saved me a lot of work! Thank you simply does not suffice. :o)

ReplyDeleteAwesome, saved a good while trying to convert some of the other highly ranked posts into excel, alsop uses the formula correctly

ReplyDeleteThanks a million!

ReplyDeleteGreetings from Warsaw, Poland.

This post continues to help people even though its really old; you have saved a lot of time for a lot of people.

ReplyDeleteThank you for your work.

Saved me a couple of hours!

ReplyDeleteThanks

thanks dude. still works in 2013!!

ReplyDeleteReally useful, many many thanks!

ReplyDeleteThanks a lot it is of great Help.....was searching a lot and ultimate answer by u......Thnks RIT

ReplyDeleteFantastic!!!!!!!!!!

ReplyDeletethanks! helped out a lot ! :)

ReplyDeleteThank you from Alaska! This saved a lot of time and made my project manageable.

ReplyDeleteIncredible. Thanks.

ReplyDeleteThanks a ton

ReplyDeleteThanks a lot! Saved us a lot of pain.

ReplyDeleteGPS tracks with holes due to GPS reception loss are my biggest enemy in my quest to GPS tag travel photos.

ReplyDeleteJGPSTrackEditandExcelwith your formula are my answer to creating missing track points with reasonable time stamps. Thanks for sharing.Immensely helpful. Just saved me a good hour of work in converting PHP code I have which does the same job into Excel. Thank you!

ReplyDeleteMany thank to you man.... U have saved my time....

ReplyDeleteThanks a lot. You surely made my job easy. Thanks.

ReplyDeleteBrilliant.

ReplyDeleteThank you!!! So helpful!!!

ReplyDelete