Thursday, May 08, 2025

Breaking News
>> Securing and encrypt View State and Cookies values  >> Page has one or more controls that do not correspond with   >> “The Controls collection cannot be modified because the control contains code blocks”  >> How to fix "Validation(): Element 'xxxx' is not supported  >> How to create a new session in ASP.NET programmatically  >> MySQL Database Backup using mysqldump command    

Editors Picks

Tuesday, June 19, 2012

distance between two latitude longitude points in c#



/// 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

Contact Us

Name

Email *

Message *