///
Loc A Longitude
///
Loc A Latitude
///
Loc B Longitude
///
Loc B Latitude
///
1=Km,2=mtr
///
public double distance(double
X1,double Y1,double
X2,double Y2,int
Flg)
{
double R =
6371;
double dLat =
this.toRadian(Y2 - Y1);
double dLon = this.toRadian(X2
- X1);
double a = Math.Sin(dLat
/ 2) * Math.Sin(dLat / 2) + Math.Cos(this.toRadian(Y1)) * Math.Cos(this.toRadian(Y2)) * Math.Sin(dLon
/ 2) * Math.Sin(dLon / 2);
double c = 2
* Math.Asin(Math.Min(1,
Math.Sqrt(a)));
double d = R
* c;
switch (Flg)
{
case 1: //km
return d;
break;
case
2: //mtr
return d *
1000;
break;
default:
return d;
break;
}
}
private double toRadian(double
val)
{
return (Math.PI / 180) * val;
}
No comments :
Post a Comment