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