This function takes latitudes and longitudes for two locations and calculates the distance (in meters) between the locations using the Haversine method.
latlon_to_km(tclat_1, tclon_1, tclat_2, tclon_2, Rearth = 6378.14)
A numeric vector giving latitude of the first location (degrees)
A numeric vector giving longitude of the first location (degrees). This value should be expressed as a positive value for Western hemisphere longitudes.
A numeric vector giving latitude of the second location (degrees)
A numeric vector giving longitude of the second location (degrees). This value should be expressed as a positive value for Western hemisphere longitudes.
Radius of the earth (km). Default is 6378.14 km.
A vector with the distance between the two locations, in kilometers.
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(\gamma) = hav(\phi_1 - \phi_2) + cos(\phi_1)*cos(\phi_2)*hav(L_1 - L_2)$$ where:
\(\phi_1\): Latitude of first location, in radians
\(\phi_2\): Latitude of second location, in radians
\(L_1\): Longitude of first location, in radians
\(L_2\): Longitude of second location, in radians
\(hav(\gamma)\): The haversine function, \(hav(\gamma) = sin^2 \left(\frac{\gamma}{2}\right)\)
\(R_earth\): Radius of the earth, here assumed to be 6378.14 kilometers
\(D\): Distance between the two locations, in kilometers