Use C # function code to calculate the distance between two points based on the latitude and longitude)

Source: Internet
Author: User

Code
Public Static DoubleDistanceoftwopoints (DoubleLng1,DoubleLAT1,DoubleLng2,Double LAT2, gausssphere GS)
{
DoubleRadlat1= Rad (LAT1 );
DoubleRadlat2= Rad (LAT2 );
DoubleA=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 )));
S = S * (GS = gausssphere. WGS84 ? 6378137.0 :( GS = gausssphere. xian80 ? 6378140.0 : 6378245.0 ));
S=Math. Round (S* 10000)/ 10000 ;
Return S;
}

Private Static DoubleRad (Double D)
{
ReturnD*Math. Pi/ 180.0;
}

Gausssphere is a custom Enumeration type
/**/ /// <Summary>
///References used in Gaussian projection
/// </Summary>
Public Enum Gausssphere
{
Beijing54,
Xian80,
WGS84,
}

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. This implementation is sufficient for space distance calculation in China, in meters .. Net2.0, C # implementation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.