Here I am going to discuss the how to calculate the distance between two points using the longitude and latitude points.
Brief history: Latitude and Longitude are imaginary lines on the globe to measure the time difference and distance difference between two points.
Latitudes are horizontal lines and Longitudes are vertical lines. By using Longitude we can easily find out the time of any place with respect to standard time GMT.
While coming to distance calculation between two points, there is a necessity to take the latitude and longitude information.
It’s better to take the values as much as possible accurately, why becz earth is not perfect round shape. There is a 45 Kms between equatorial to poles, actually this is angular difference. So, we need to consider this factor while design the GIS kind of applications.
I am going to explain the things from the program..
The program take the latitude/longitude points in the form of decimal format.
It’s calculate the radiant value from the decimal inputs.
After we need to calculate the central spherical value(it’s accurate calculation for angular difference between locations)
Return the value in the kilometers
public string distanceinKms(double Latitude1, double Longitude1, double Latitude2, double Longitude2)
{
//mention the constant values
double C_RADIUS_EARTH_KM = 6371.1;
double C_RADIUS_EARTH_MI = 3958.82;
double C_PI = 3.14159265358979;
//actual story begins
double Lat1;
double Lat2;
double Long1;
double Long2;
long X;
double Delta;
X = 1;
//convert to decimal degree
Lat1 = Latitude1 * X;
Long1 = Longitude1 * X;
Lat2 = Latitude2 * X;
Long2 = Longitude2 * X;
//convert to radians: radians = (degrees/180) * PI
Lat1 = (Lat1 / 180) * C_PI;
Lat2 = (Lat2 / 180) * C_PI;
Long1 = (Long1 / 180) * C_PI;
Long2 = (Long2 / 180) * C_PI;
//get the central spherical angle
Delta = ((2 * ArcSin(Math.Sqrt(Math.Pow(Math.Sin((Lat1 - Lat2)/2),2) + Math.Cos(Lat1) * Math.Cos(Lat2) * Math.Pow(Math.Sin((Long1 - Long2) / 2),2)))));
//return the distance in kilo meters
return (Delta * C_RADIUS_EARTH_KM).ToString();
}
public double ArcSin(double X)
{
//ArcSin function. Improvise.
return Math.Atan(X / Math.Sqrt(-X * X + 1));
}
Observation:
First Location Values:
Country: PORT LOUIS
Latitufe: 20-08'S= -20.133333
Longitude: 57-29'E= 57.483333
Second Location Values:
Country: SAINT DENIS
Latitufe: 20-52'S= -20.866667
Longitude: 55-28'E= 55.466667
It’s required to pass the parameters like this
string sdskm = distanceinKms(-20.133333, 57.483333, -20.866667, 55.466667);
The output will be become 225.315719359445
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment