Description Usage Arguments Details Value
View source: R/latlon_helpers.R
This function takes latitudes and longitudes for two locations and calculates the distance (in meters) between the locations using the Haversine method.
1 | latlon_to_km(tclat_1, tclon_1, tclat_2, tclon_2, Rearth = 6378.14)
|
tclat_1 |
A numeric vector giving latitude of the first location (degrees) |
tclon_1 |
A numeric vector giving longitude of the first location (degrees). This value should be expressed as a positive value for Western hemisphere longitudes. |
tclat_2 |
A numeric vector giving latitude of the second location (degrees) |
tclon_2 |
A numeric vector giving longitude of the second location (degrees). This value should be expressed as a positive value for Western hemisphere longitudes. |
Rearth |
Radius of the earth (km). Default is 6378.14 km. |
This function uses the Haversine method with great circle distance to calculate this distance. It is applying the following equations to determine distance (in kilometers) between two latitude-longitude pairs:
hav(γ) = hav(φ1 - φ2) + cos(φ1)*cos(φ2)*hav(L1 - L2)
where:
φ1: Latitude of first location, in radians
φ2: Latitude of second location, in radians
L1: Longitude of first location, in radians
L2: Longitude of second location, in radians
hav(γ): The haversine function, hav(γ) = sin^2 (γ / 2)
Rearth: Radius of the earth, here assumed to be 6378.14 kilometers
D: Distance between the two locations, in kilometers
A vector with the distance between the two locations, in kilometers.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.