haversine | R Documentation |
Calculates the shortest distance between two points on the Earth's surface using the Haversine formula, also known as the great-circle distance or "as the crow flies".
haversine(lat_from, lon_from, lat_to, lon_to, r = 6378137)
lat_from |
Numeric. Latitude(s) of the starting point(s) in decimal degrees (EPSG:4326). |
lon_from |
Numeric. Longitude(s) of the starting point(s) in decimal degrees (EPSG:4326). |
lat_to |
Numeric. Latitude(s) of the destination point(s) in decimal degrees (EPSG:4326). |
lon_to |
Numeric. Longitude(s) of the destination point(s) in decimal degrees (EPSG:4326). |
r |
Numeric. Radius of the Earth in meters (default = 6378137). |
The Haversine ('half-versed-sine') formula was published by R.W. Sinnott in 1984, although it has been known for much longer.
This function is fully vectorized: if multiple coordinates are supplied, it returns a distance for each pair of points.
A numeric vector with distances in the same unit as r
(default in meters).
Martin Haringa
Sinnott, R.W, 1984. Virtues of the Haversine. Sky and Telescope 68(2): 159.
# Single pair
haversine(53.24007, 6.520386, 53.24054, 6.520386)
# Vectorized usage
lat_from <- c(53.24, 52.37)
lon_from <- c(6.52, 4.90)
lat_to <- c(48.85, 51.92)
lon_to <- c(2.35, 4.48)
haversine(lat_from, lon_from, lat_to, lon_to)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.