Skip to content

Instantly share code, notes, and snippets.

@matthews-p
Created November 27, 2024 17:58
Show Gist options
  • Save matthews-p/48e0408c0392e48ea1d948963bffda3c to your computer and use it in GitHub Desktop.
Save matthews-p/48e0408c0392e48ea1d948963bffda3c to your computer and use it in GitHub Desktop.
GetDistanceMiles
/** GetDistanceMiles */
/*
FUNCTION NAME: GetDistanceMiles
DESCRIPTION: Returns the distance in miles between points X and Y based on their
decimal latitude and longitude coordinates
ARGS:
LatX: Point X's decimal latitude
LngX: Point X's decimal longitude
LatY: Point Y's decimal latitude
LngY: Point Y's decimal longitude
EXAMPLE:
=GetDistanceMiles(39.4567,-109.123,33.789,-120.3456)
*/
GetDistanceMiles = LAMBDA(
LatX,
LngX,
LatY,
LngY,
ACOS(
COS(RADIANS(LatX)) * COS(RADIANS(LatY)) * COS(RADIANS(LngY - LngX)) +
SIN(RADIANS(LatX)) * SIN(RADIANS(LatY))
) * 3959
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment