Method for calculating the distance


Is there any api or package in R to calculate the distance between the two locations given their lattitudes and longitudes ?


Hey @gurchetan1000,

I found two interesting packages -

  1. gmapsdistance uses Google Maps API to calculate the distance between given coordinates. You can find more detail with a bunch of examples here -

Pro - You can use different traveling modes like “driving”, “walking” or "bicycling"
Catch - You need to have an API key from gmaps.(You can get it from here)

  1. Also, geosphere looks promising. It has a set of different algorithms to calculate distance.

Hope this helps,
Sanad :slight_smile:


Use haversine() for direct distance calculation