I am using this formula found here Calculating speed from set of longitude and latitudes values obtained in one minute? and then converted it to Delphi (11) Pascal.
My aim is to determine meters traveled per second in a moving car. Therefore the curvature of the earth in relation to this very short distance travelled can be ignored (for my purposes).
My pascal attempt at the above Java code has a flaw in it, because it is calculating the distance at +/- twice the actual distance than what it should actually be.
Please help me to correct/improve my Delphi formula that calculates the meters traveled (dDistance) between first point (dLat1, dLon1) and second point (dLat2, dLon2).
I am also wondering if my source (see above link) is actually ideal code, but I don't have the math skill to compare my source formula against other formulas like for instance = Calculate distance between two latitude-longitude points? (Haversine formula)
(Don't worry about the speed calculation, my request is only for the distance calculation please).
const degToRad = System.Pi / 180;
iEarthRadius = 6371000;// meters
var dDistance, dSpeed, dLat1, dLon1, dLat2, dLon2 : double;
begin
dDistance := iEarthRadius * degToRad *
System.Sqrt(System.Math.Power(System.Math.Cosecant(dLat1 * degToRad )
* (dLon1 - dLon2) , 2) + System.Math.Power(dLat1 - dLat2, 2));
end;