#' Calculate Haversine distance using data.table framework
#' @export
dtHaversine <-
function(lat_from, lon_from, lat_to, lon_to, r = 6378137) {
radians <- pi / 180
lat_to <- lat_to * radians
lat_from <- lat_from * radians
lon_to <- lon_to * radians
lon_from <- lon_from * radians
dLat <- (lat_to - lat_from)
dLon <- (lon_to - lon_from)
a <-(sin(dLat / 2) ^ 2) + (cos(lat_from) * cos(lat_to)) * (sin(dLon / 2) ^2)
return(2 * atan2(sqrt(a), sqrt(1 - a)) * r)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.