R calculating distance between 2 points on earth using package geosphere

user2543622 picture user2543622 · May 25, 2016 · Viewed 13.7k times · Source

My question is based upon this question. Using it I wrote below code where first set of coordinates are for LGA airport NY while second set of coordinates are for EWR airport NY. I get the answer 33713. Is that in miles or in kilometers? A quick google check says that the distance should be 33 miles (but it is not a straigh line/arc distance :( It is a distance by road). The package documentation says that the answers are in meters. Please clarify. Is this a good method to find the distance on Earth given 2 coordinates? How can I get answer in Miles?

library(geosphere)
distm (c(40.777250, -73.872610), c(40.6895, -74.1745), fun = distHaversine)
         [,1]
[1,] 33713.61

Answer

Edward R. Mazurek picture Edward R. Mazurek · May 25, 2016

Yes, it's giving you the answer in meters. To convert to miles:

> distm(c(40.777250, -73.872610), c(40.6895, -74.1745), fun = distHaversine)[,1] / 1609
[1] 20.95315

20.95 miles as the crow flies.