Finding the nearest lat and long with an array formula

samcd87

New Member
Joined
Apr 8, 2022
Messages
14
Office Version
  1. 365
Platform
  1. Windows
  2. Web
I have two sets of co-ordinates, one set shows landmarks and another set shows points where I want to find the nearest landmark to them.

For example;

LandmarkLatLongPointsLatLongNearest Landmark
Landmark A53.5168292-2.2036031Point 153.5171561-2.2036183Landmark A
Landmark B53.5170875-2.2032919

There is more data than this, but this is an example of the layout.

For the vast majority of the points I have, I've done some sense checks on a map and they are fine. But for a handful, the wrong result appears.

For example above, Point 1 is closer to Landmark B, but Landmark A is given as the result.

The formula in H2 (nearest landmark) is =INDEX($A$1:$A$6476,MATCH(MIN(SQRT(($B$1:$B$6476-F2)^2+($C$1:$C$6476-G2)^2)),SQRT(($B$1:$B$6476-F2)^2+($C$1:$C$6476-G2)^2),0),1)
and this is copied down to all points. I got this formula from here.

Can anybody suggest why this might be happening please - and why it's only happening in some instances?

Any help appreciated!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
In this case, point 1 looks closer to landmark A to me. Here's my go at it.

MrExcelPlayground12.xlsx
ABCDEFGHIJ
2LandmarkLatLongPointsLatLongNearest Landmark
3Landmark A53.5168-2.2036Point 153.517156-2.2036Landmark A0.000327
4Landmark B53.5171-2.20330.000334
Sheet26
Cell Formulas
RangeFormula
H3H3=INDEX(SORTBY($A$3:$A$4,SQRT((F3-$B$3:$B$4)^2+(G3-$C$3:$C$4)^2)),1)
J3:J4J3=SQRT((F3-B3:B4)^2+(G3-C3:C4)^2)
Dynamic array formulas.
 
Upvote 0
Thanks for the reply,

When I use an online calculator to measure the distance from Point 1 to the two landmarks, I get 36.36 metres to Landmark A and 22.89 metres to Landmark B.
 
Upvote 0

Forum statistics

Threads
1,215,335
Messages
6,124,326
Members
449,155
Latest member
ravioli44

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