View source: R/haversine_distance_function.R
hav_dist | R Documentation |
This function computes the great circle distance between two points (long, lat).
Computations default to kilometers (for the WGS84 ellipsoid).
This code was adapted from https://en.wikipedia.org/wiki/Great-circle_distance;
https://en.wikipedia.org/wiki/Haversine_formula; and http://www.movable-type.co.uk/scripts/latlong.html
See also, in the geosphere package https://cran.r-project.org/web/packages/geosphere/geosphere.pdf:
distm(p1, p2, fun = distVincentyEllipsoid) and distHaversine()
hav_dist(long1, lat1, long2, lat2, radius = 6371)
long1 |
longitude for first point |
lat1 |
latitude for first point |
long2 |
longitude for second point |
lat2 |
latitude for first point |
radius |
the radius of the earth; units of computed distance will be the same as the units of R. Dafaults to 6371 kilometers. |
hav_dist(0,0,45,45)
distHaversine(c(0,0), c(45,45))/1000
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.