Unit: m
Util. distancebylnglat = function (lng1, LAT1, lng2, LAT2)
{
VaR radlat1 = util. Rad (LAT1 );
VaR radlat2 = util. Rad (LAT2 );
VaR A = radlat1-radlat2;
VaR B = util. Rad (lng1)-util. Rad (lng2 );
VaR S = 2 * Math. asin (math. SQRT (math. pow (math. sin (A/2), 2) + math. cos (radlat1) * Math. cos (radlat2) * Math. pow (math. sin (B/2), 2 )));
S = S * 6378137.0;
S = math. Round (S * 10000)/10000;
Return S;
}
Util. Rad = function (d)
{
Return D * Math. PI/180.0;
}
Note
Math. SQRT (x): the square root of X
Math. Pow (x, n): returns the nth power of X.
Math. Cos (x): returns the cosine of X.
Math. Sin (x): sine function of X
Math. asin (y): arcsin function of X
Math. Round (x): returns the value closest to integer x.
6378137: long radius
Coordinate System
WGS-84 World Earth coordinate system (wor1d geodetic system ). Coordinate System
The implementation of distance between two points on the earth's surface based on the latitude and longitude obtained from Google map is slightly adapted. For space distance calculation in China, this implementation is sufficient, in meters .. Net2.0, C # implementation.
Public static double distanceoftwopoints (double lng1, double LAT1, double lng2, double LAT2, gausssphere GS)
{
Double radlat1 = rad (LAT1 );
Double radlat2 = rad (LAT2 );
Double A = radlat1-radlat2;
Double B = rad (lng1)-rad (lng2 );
Double S = 2 * Math. asin (math. SQRT (math. pow (math. sin (A/2), 2) + math. cos (radlat1) * Math. cos (radlat2) * Math. pow (math. sin (B/2), 2); string 8
S = S * (GS = gausssphere. WGS84? 6378137.0: (GS = gausssphere. xian80? 6378140.0: 6378245.0 ));
S = math. Round (S * 10000)/10000;
Return S;
}
Private Static double rad (double D)
{
Return D * Math. PI/180.0;
}
Gausssphere is a custom Enumeration type
/// <Summary>
/// Reference elliptical in Gaussian projection
/// </Summary>
Public Enum gausssphere
{
Beijing54,
Xian80,
WGS84,
}
Shenzhen Universiade-Shenzhen 2011 Summer Universiade