Mega Code Archive

 
Categories / C# / Development Class
 

Calculate Distance between two points

using System; using System.Collections.Generic; using System.Linq; using System.Text; public class Utility {     public static double CalculateDistance(double pStartLat, double pStartLong, double pEndLat, double pEndLong)     {         double distance = /*for conversion in Metres*/                            1000 *             /*radius of earth in km*/                            6378.7 * Math.Acos(Math.Sin(pStartLat / 57.2958)                                   * Math.Sin(pEndLat / 57.2958)                                   + Math.Cos(pStartLat / 57.2958)                                   * Math.Cos(pEndLat / 57.2958)                                   * Math.Cos((pEndLong / 57.2958) - (pStartLong / 57.2958)));         return distance;     } }