Groovy web console

subscribe to the feed Subscribe
to this
site
distance calculator (via #groovywebconsole)
tweet this snippet Tweet
this
script

distance calculator

Published 6 months ago by Javi
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def lat1 = 
def lat2 = 
def lon1 =
def lon2 =

 double R = 6372.8
        // In kilometers
        double dLat = Math.toRadians(lat2 - lat1)
        double dLon = Math.toRadians(lon2 - lon1)
        lat1 = Math.toRadians(lat1)
        lat2 = Math.toRadians(lat2)

        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2)
        double c = 2 * Math.asin(Math.sqrt(a))
        double value = R * c
return value