I have calculated the nearest location between two points based on the given latitude and longitude using geosphere. The issue I have is the distance is not in kilometers or meters. How can I get the calculated distance in KM or M?
my original dataset
t1 <-
structure(list(UML_ID = c("PO1000008590", "Submitted to WRI for review",
"PO1000003711", "PO1000004269", "PO1000008154"), Latitude = c(17.00352,
7.2, 1.545386, 2.051269, 2.11272), Longitude = c(81.46973, -2.1173,
104.209347, 100.252339, 100.27311), Country = c("India", "Ghana",
"Malaysia", "Indonesia", "Indonesia")), row.names = c(NA, -5L
), class = c("tbl_df", "tbl", "data.frame"))
library(geosphere)
d.t1 <- distm(t1[,c('Longitude','Latitude')], fun = distGeo)
min.d.t1 <- apply(d.t1, 1, function(x) order(x, decreasing = F)[2])
new.t1 <- cbind(t1, t1[min.d.t1,], apply(d.t1, 1, function(x) sort(x,decreasing = F)[2]))
colnames(new.t1) <- c(colnames(t1), paste("n.", colnames(t1)), "Distance")
However the distance I get are not in KM nor m.