haversine: Great-circle (Haversine) distance

View source: R/distance.R

haversineR Documentation

Great-circle (Haversine) distance

Description

Vectorized great-circle distance between longitude/latitude points. Arguments are recycled to a common length, so any may be length 1.

Usage

haversine(lon1, lat1, lon2, lat2, radius = 6371.0088)

Arguments

lon1, lat1, lon2, lat2

Numeric vectors of coordinates in decimal degrees.

radius

Sphere radius in the desired output units. Defaults to the mean Earth radius, 6371.0088 km, so distances are returned in kilometres.

Value

A numeric vector of distances. NA in any coordinate gives NA.

Examples

haversine(0, 0, 0, 1)          # ~111 km per degree of latitude
haversine(7.4, 9.1, 8.5, 12.0) # Abuja-ish to Kano-ish


palsr documentation built on July 1, 2026, 5:07 p.m.