Here you can find the source of calculateDistance(lat2, lon2)
/* calculateDistance() function adapted from * latitude/longitude spherical geodesy formulae & scripts * (c) Chris Veness 2002-2010//from w w w . j av a2 s .c o m * www.movable-type.co.uk/scripts/latlong.html */ function calculateDistance(lat2, lon2) { var R = 3959; // radius of Earth in miles var lat1 = 47.3193057; var lon1 = -93.2895824; var dLat = (lat2 - lat1).toRad(); var dLon = (lon2 - lon1).toRad(); var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * Math.sin(dLon / 2) * Math.sin(dLon / 2); var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); var d = Math.round(R * c); return d; }
exports.distance = function(lat1, lon1, lat2, lon2) { var radlat1 = Math.PI * lat1/180; var radlat2 = Math.PI * lat2/180; var radlon1 = Math.PI * lon1/180; var radlon2 = Math.PI * lon2/180; var theta = lon1-lon2; var radtheta = Math.PI * theta/180; var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta); dist = Math.acos(dist); ...
function distance(lat1, lon1, lat2, lon2) { var R = 6371; var a = 0.5 - Math.cos((lat2 - lat1) * Math.PI / 180)/2 + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * (1 - Math.cos((lon2 - lon1) * Math.PI / 180))/2; var m = R * 2 * Math.asin(Math.sqrt(a))*1000; return Math.floor(m);
function distance(lat1,lon1,lat2,lon2) { var R = 6371; var dLat = deg2rad(lat2-lat1); var dLon = deg2rad(lon2-lon1); var 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) ; ...
function Point(x, y) { this.x = x; this.y = y; function randomPoint() { var randomx = randomNumber(WIDTH); var randomy = randomNumber(HEIGHT); var randomPoint = new Point(randomx, randomy); return randomPoint; ...