Formula to calculate distance between locations given Lat and Long

leebauman

Board Regular
Joined
Jul 1, 2004
Messages
194
Office Version
  1. 365
Platform
  1. Windows
My data consists of hundreds of Latitude and Longitude location coordinates; I need to know distance (in miles) from each location to the location which is closest and the location which is furthest away:

Excel 2010 32 bit
E
F
G
H
I
11
Location
Lat
Long
Distance to closest location
Distance to furthest location
12
A​
34.4340498​
-119.8517606​
13
B​
34.4388717​
-119.8086146​
14
C​
34.4325943​
-119.8504486​
15
D​
34.1693802​
-118.4502411​
16
E​
34.1530838​
-118.2308807​
17
F​
34.238292​
-118.561477​
Sheet: Sheet1

Is this possible?

I appreciate any help and suggestions. Thanks!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Book1
CDEFGH
17LATLONGnearest airportNearest distance km
1834.83257949-86.46106284"Madison County Executive Airport-Tom Sharp Jr Field"9.3660237
1946.0827835914.51387535"Ljubljana Railway Station"2.6564075
2032.47986191-85.64240964"Moton Field Municipal Airport"4.1297374
2131.092847-17.931806"Funchal Cruise Terminal"197.35917
2211.95-66"La Orchila Airport"25.18078
2346.0510179614.50659327"Ljubljana Railway Station"1.0100758
2446.0640028614.50899856"Ljubljana Railway Station"0.6496917
2546.0655214.543091"Ljubljana Railway Station"2.4282363
2646.06562914.543439"Ljubljana Railway Station"2.4574973
2746.2367625914.37318777"Ljubljana Joe Pucnik Airport"6.6534809
2846.05236114.514183"Ljubljana Railway Station"0.7318904
Sheet1
Cell Formulas
RangeFormula
H18=ACOS(COS(RADIANS(90-C18)) * COS(RADIANS(90-INDEX(DB_loc[Latitude],MATCH(Sheet1!F18,DB_loc[Name],0)))) + SIN(RADIANS(90-C18)) * SIN(RADIANS(90-INDEX(DB_loc[Latitude],MATCH(Sheet1!F18,DB_loc[Name],0)))) * COS(RADIANS(D18-INDEX(DB_loc[Longitude],MATCH(Sheet1!F18,DB_loc[Name],0))))) * 6371
F18{=INDEX(DB_loc[Name],MATCH(SMALL((ABS(C18-DB_loc[Latitude])^2+ABS(D18-DB_loc[Longitude])^2)^(0.5),1),(ABS(C18-DB_loc[Latitude])^2+ABS(D18-DB_loc[Longitude])^2)^(0.5),0))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0

Book1
BCDEFGHIJKLMN
2IDNameCityCountryIATAICAOLatitudeLongitudeAltitudeTimezoneDSTTz DatabaseType
31"Goroka Airport""Goroka""Papua New Guinea""GKA""AYGA"-6.081689834590001145.391998291528210"U""Pacific/Port_Moresby""airport"
410"Thule Air Base""Thule""Greenland""THU""BGTL"76.5311965942-68.7032012939251-4"E""America/Thule""airport"
5100"Ottawa Macdonald-Cartier International Airport""Ottawa""Canada""YOW""CYOW"45.3224983215332-75.66919708251953374-5"A""America/Toronto""airport"
61000"Faya Largeau Airport""Faya-largeau""Chad""FYT""FTTY"17.9171009063720719.1110992431640627711"N""Africa/Ndjamena""airport"
DB
 
Upvote 0
Hi Macropod, yes I did. My formula is :

=MIN(ACOS(SIN(RADIANS(C2))*SIN(RADIANS($C$2:$C$524))+COS(RADIANS(C2))*COS(RADIANS($C$2:$C$524))*COS(RADIANS(C2-$D$2:$D$524))))*6367,465

LATLONGNearest distance km
46,0554116714,505158532.260
46,0827835914,513875352.261
46,074366314,48586912.261
46,0510179614,506593272.259
46,0510179614,506593272.259
46,0510179614,506593272.259

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Well, aside from the fact you have a mistake in the formula (your final C2 should be D2) and that the last 3 locations in post 24 are the same, you're evidently trying to compare distances between cells within $C$2:$D$524 against themselves instead of against cells outside that range - as is clearly shown in the demo workbook in the linked thread. So, even if you fix the formula, you'll essentially get 0 (bear in mind my comments about accuracy at very small distances in the linked thread) for all rows because of the way you're doing things.
 
Upvote 0

Forum statistics

Threads
1,218,080
Messages
6,140,340
Members
450,279
Latest member
nrc0710

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