2014년 9월 29일 월요일

Calculation of two point distance from location sensor

Calculation of two point distance from location sensor.

Unit of result value is a km.

function TForm1.CalcDistance( lon1, lat1,  lon2, lat2 : single ) : single;
var
   theta, dist : double;  

begin
   theta := lon1 - lon2;
   dist := sin( degTorad(lat1)) * sin(degTorad(lat2)) + cos(degTorad(lat1)) * cos(degTorad(lat2)) * cos(degTorad(theta));
   dist := arccos(dist);
   dist := radTodeg(dist);
   dist := dist * 60 * 1.1515;
   dist := dist * 1.609344;
   result := dist;
end;

댓글 없음:

댓글 쓰기