C # Calculates the distance of two latitude and longitude

Source: Internet
Author: User

 Earth radius, Unit m Private Const double Earth_radius = 6378137;        <summary>///Calculate the distance of two points, return the distance of two points, Unit meter///The formula is provided by Google, the error is less than 0.2 meters//</summary> <param name= "LAT1" > 1th latitude </param>//<param name= "lng1" > 1th longitude </param>//<pa Ram Name= "LAT2" > 2nd latitude </param>//<param name= "Lng2" > 2nd longitude </param>//<returns>&            lt;/returns> public static double getdistance (double lat1, double lng1, double lat2, double lng2) {            Double RADLAT1 = Rad (LAT1);            Double radLng1 = Rad (lng1);            Double radLat2 = Rad (LAT2);            Double radLng2 = Rad (lng2);            Double A = RADLAT1-RADLAT2;            Double b = radlng1-radlng2; Double result = 2 * Math.asin (MATH.SQRT (Math.pow (Math.sin (A/2), 2) + Math.Cos (RADLAT1) * MATH.COS (RADLAT2) * MATH.POW (Ma Th.            Sin (B/2), 2)) * Earth_radius;        return result;     }   <summary>///latitude/longitude converted to radians///</summary>//<param name= "D" ></param> <returns></returns> private static Double Rad (double D) {return (double) d *        math.pi/180d; }

  

C # Calculates the distance of two latitude and longitude

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.