Distance calculation between longitude and latitude

Source: Internet
Author: User
Tags cos

///   <Summary>
/// Distance between longitude and latitude
///   </Summary>
///   <Param name = "lng1"> Longitude, usually greater than 90 </Param>
///   <Param name = "LAT1"> Latitude, usually less than 90 </Param>
///   <Param name = "lng2"> </param>
///   <Param name = "LAT2"> </param>
///   <Param name = "gS"> The default value is WGS84. </Param>
///   <Returns> </returns>
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 (/ 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 (DoubleD)
{
ReturnD * Math. PI/180.0;
}

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

 

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.