-
1
- #1
ceoautofusion
Programmer
thread184-1621436
Here is the working foxpro code...
lnlat1 = 32.61
lnlon1 = -117.07
lnlat2 = 33.12
lnlon2 = -117.09
lnR = 3958.7558657440545 && Radius of earth in Miles
lnLat = DTOR(lnLat2 - lnLat1)
lnLon = DTOR(lnLon2-lnLon1)
lnA = SIN(lnLat / 2) * SIN(lnLat / 2) + COS(DTOR(lnLat1)) * ;
COS(DTOR(lnLat2)) * SIN(lnLon / 2) * SIN(lnLon / 2)
lnC = 2 * ATN2(SQRT(lnA), SQRT(1 - lnA))
lnD = lnR * lnC && distance between the points in km.
? lnD
RETURN
Here is the equivalent Javascript Code
lat1 = 32.61;
lon1 = -117.07;
lat2 = 33.12;
lon2 = -117.09;
//Radius of the earth in: 1.609344 miles, 6371 km | var R = (6371 / 1.609344);
var R = 3958.7558657440545; // Radius of earth in Miles
var dLat = toRad(lat2-lat1);
var dLon = toRad(lon2-lon1);
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
document.write(d);
function toRad(Value) {
/** Converts numeric degrees to radians */
return Value * Math.PI / 180;
}
Distance should be 35.256706166892230
Here is the working foxpro code...
lnlat1 = 32.61
lnlon1 = -117.07
lnlat2 = 33.12
lnlon2 = -117.09
lnR = 3958.7558657440545 && Radius of earth in Miles
lnLat = DTOR(lnLat2 - lnLat1)
lnLon = DTOR(lnLon2-lnLon1)
lnA = SIN(lnLat / 2) * SIN(lnLat / 2) + COS(DTOR(lnLat1)) * ;
COS(DTOR(lnLat2)) * SIN(lnLon / 2) * SIN(lnLon / 2)
lnC = 2 * ATN2(SQRT(lnA), SQRT(1 - lnA))
lnD = lnR * lnC && distance between the points in km.
? lnD
RETURN
Here is the equivalent Javascript Code
lat1 = 32.61;
lon1 = -117.07;
lat2 = 33.12;
lon2 = -117.09;
//Radius of the earth in: 1.609344 miles, 6371 km | var R = (6371 / 1.609344);
var R = 3958.7558657440545; // Radius of earth in Miles
var dLat = toRad(lat2-lat1);
var dLon = toRad(lon2-lon1);
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
document.write(d);
function toRad(Value) {
/** Converts numeric degrees to radians */
return Value * Math.PI / 180;
}
Distance should be 35.256706166892230