Learn R Programming

skm (version 0.1.5.4)

dist_wlatlng: dist_wlatlng

Description

calculate distance btwn coordinate1 and coordinate2

Usage

dist_wlatlng(.lat1, .lng1, .lat2, .lng2, .measure = "mi")

Arguments

.lat1
latitude of coordinate1
.lng1
longitude of coordinate1
.lat2
latitude of coordinate2
.lng2
longitude of coordinate2
.measure
- mi or km

Details

calculate the great circle distance between 2 points with Haversine formula, which deliberately ignores elevation differences.

Haversine formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159):

dlon = lon2 - lon1

dlat = lat2 - lat1

a = sin^2(dlat/2) + cos(lat1) * cos(lat2) * sin^2(dlon/2)

c = 2 * arcsin(min(1,sqrt(a)))

d = R * c