Calculate distance in km between 2 coordinates (longitude ,latitude)

Samir_

New Member
Joined
Jul 12, 2023
Messages
3
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
Platform
  1. Windows
Hi
I need a formula in excel 365 to find the distance in km between two coordinates (longitude ,latitude)

I had tried these twos formulas
=6371 * ACOS(COS(RADIANS(90-B2)) * COS(RADIANS(90-B3)) + SIN(RADIANS(90-B2)) * SIN(RADIANS(90-B3)) * COS(RADIANS(A2-A3)))
=2*ASIN(SQRT((SIN((B3-B2)/2))^2+COS(B2)*COS(B3)*(SIN((A3-A2)/2))^2))*6371

But they are not giving the same result and they did not match the result in google maps

TIA

-Samir
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Are you looking at the distance in a straight line or via roads?

Do you have a Google API key/ account?
Do you have a HERE maps API key/ account?
 
Upvote 0
The below seems to do it, which is what you had:
Book1
ABCDEF
1LatLongKM'sMiles
2From51.406710.40932658.0182914.982334
3To51.366380.5051189
Sheet1
Cell Formulas
RangeFormula
E2E2=6371*ACOS(COS(RADIANS(90-B2))*COS(RADIANS(90-B3))+SIN(RADIANS(90-B2))*SIN(RADIANS(90-B3))*COS(RADIANS(C2-C3)))
F2F2=E2*0.621371


Checked on the below
Calculate distance and bearing between two Latitude/Longitude points using haversine formula in JavaScript

Maybe you could explain more and possibly provide the lat longs you are working with and the discrepancy you are having?
 
Upvote 0
Solution
The below seems to do it, which is what you had:
Book1
ABCDEF
1LatLongKM'sMiles
2From51.406710.40932658.0182914.982334
3To51.366380.5051189
Sheet1
Cell Formulas
RangeFormula
E2E2=6371*ACOS(COS(RADIANS(90-B2))*COS(RADIANS(90-B3))+SIN(RADIANS(90-B2))*SIN(RADIANS(90-B3))*COS(RADIANS(C2-C3)))
F2F2=E2*0.621371


Checked on the below
Calculate distance and bearing between two Latitude/Longitude points using haversine formula in JavaScript

Maybe you could explain more and possibly provide the lat longs you are working with and the discrepancy you are having?

Thank you. that's works well and the link was very helpful
 
Upvote 0

Forum statistics

Threads
1,223,881
Messages
6,175,159
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top