Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save asjadathick/f20c60565f8b152987d16eade8a4b1de to your computer and use it in GitHub Desktop.

Select an option

Save asjadathick/f20c60565f8b152987d16eade8a4b1de to your computer and use it in GitHub Desktop.
Find the distance in KM from 2 geo points
double deg2rad(def deg) {
return deg * (Math.PI/180)
}
double getDistanceFromLatLonInKm(def lat1,def lon1,def lat2,def lon2) {
def R = 6371; // Radius of the earth in km
def dLat = deg2rad(lat2-lat1); // deg2rad below
def dLon = deg2rad(lon2-lon1);
def a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2)
;
def c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
def d = R * c; // Distance in km
return d;
}
return getDistanceFromLatLonInKm(-27.3942144,153.1196363,-37.6690123,144.8388333);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment