My Smartapp, under development atm, can determine at any given moment the current Lat/Lon position of my mobile. It also has the Lat/Lon coordinates of my home. My question is, is it possible within groovy , to calculate the distance between the current mobile position and my home? I already have this ability within JS but not sure how I could use (or call) such script within my smartapp.

In case you are wondering. Here is the JS function used to calc the distance

var R2D = 180 / Math.PI;

var D2R = Math.PI / 180;

/**************************************************************************************************/

function groundDistance(toLat,toLon,fromLat,fromLon) {

toLatRad = toLat * D2R

toLonRad = toLon * D2R

fromLatRad = fromLat * D2R

fromLonRad = fromLon * D2R

x = (Math.sin(fromLatRad) * Math.sin(toLatRad)) + (Math.cos(fromLatRad) * Math.cos(toLatRad) * Math.cos(fromLonRad - toLonRad))

if(x >= 1)

return 0

else

return 60 * ((Math.atan(-x / Math.sqrt(-x * x + 1)) + 2 * Math.atan(1)) * R2D)

}