C # Gets the distance between two points (latitude and longitude representation)

Source: Internet
Author: User
Tags cos

#region get the distance between two points (latitude and longitude representation)
<summary>
Get the distance between two points (latitude and longitude representation)
</summary>
<param name= "P1lat" > 1th latitude Value </param>
<param name= "P1LNG" > 1th longitude Value </param>
<param name= "P2lat" > 2nd latitude Value </param>
<param name= "P2LNG" > 2nd longitude Value </param>
<returns></returns>
public static double Getdistance (double P1lat, double p1lng, double P2lat, double p2lng)
{
Double Dlat1inrad = P1lat * (math.pi/180);
Double Dlong1inrad = p1lng * (math.pi/180);
Double Dlat2inrad = P2lat * (math.pi/180);
Double Dlong2inrad = p2lng * (math.pi/180);
Double dlongitude = Dlong2inrad-dlong1inrad;
Double dlatitude = Dlat2inrad-dlat1inrad;
Double A = Math.pow (Math.sin (DLATITUDE/2), 2) + Math.Cos (dlat1inrad) * MATH.COS (Dlat2inrad) * MATH.POW (Math.sin (DLongitu DE/2), 2);
Double c = 2 * MATH.ATAN2 (MATH.SQRT (a), math.sqrt (1-a));
Double ddistance = earthradiuskm * C;
return ddistance;
}
<summary>
Radius of the Earth
</summary>
public static Double earthradiuskm = 6378.137; WGS-84
#endregion

C # Gets the distance between two points (latitude and longitude representation)

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.