Guest User

Untitled

a guest
Oct 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. # Patch number to do radians conversion
  2. Number.prototype.toRad= ->
  3. return this * Math.PI / 180;
  4.  
  5. #takes lat/lng in format 50.000 / 0.5400, returns distance in KM
  6. geodistance= (lat1,lon1,lat2,lon2)->
  7. R = 6371; # Earth Radius
  8. dLat = (lat2-lat1).toRad()
  9. dLon = (lon2-lon1).toRad()
  10. lat1 = lat1.toRad()
  11. lat2 = lat2.toRad()
  12.  
  13. a = Math.sin(dLat/2) * Math.sin(dLat/2) +
  14. Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
  15. c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  16. R * c
Add Comment
Please, Sign In to add comment