Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Patch number to do radians conversion
- Number.prototype.toRad= ->
- return this * Math.PI / 180;
- #takes lat/lng in format 50.000 / 0.5400, returns distance in KM
- geodistance= (lat1,lon1,lat2,lon2)->
- R = 6371; # Earth Radius
- dLat = (lat2-lat1).toRad()
- dLon = (lon2-lon1).toRad()
- lat1 = lat1.toRad()
- lat2 = lat2.toRad()
- a = Math.sin(dLat/2) * Math.sin(dLat/2) +
- Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
- c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
- R * c
Add Comment
Please, Sign In to add comment