![]() ![]() In my case it was best to calculate this in SQL Server, since i wanted to take current location and then search for all zip codes within a certain distance from current location. Private static double HaversineInKM(double lat1, double long1, double lat2, double long2)ĭouble a = Math.Pow(Math.Sin(dlat / 2D), 2D) + Math.Cos(lat1 * _d2r) * Math.Cos(lat2 * _d2r) * Math.Pow(Math.Sin(dlong / 2D), 2D) ĭouble c = 2D * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1D - a)) ![]() ![]() Return (int)(1000D * HaversineInKM(lat1, long1, lat2, long2)) Private static int HaversineInM(double lat1, double long1, double lat2, double long2) Static double _eQuatorialEarthRadius = 6378.1370D Return (1000.0 * HaversineInKM(lat1, long1, lat2, long2)) įunction HaversineInKM(lat1, long1, lat2, long2) In Javascript var _eQuatorialEarthRadius = 6378.1370 įunction HaversineInM(lat1, long1, lat2, long2) Return (angle * RADIO) * 0.62137 //distance in miles Public static double DistanceBetweenPlaces(ĭouble a = (Math.Sin(dlat / 2) * Math.Sin(dlat / 2)) + Math.Cos(Radians(lat1)) * Math.Cos(Radians(lat2)) * (Math.Sin(dlon / 2) * Math.Sin(dlon / 2)) ĭouble angle = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)) / Calculate the distance between two places. Here is the c# implementation of the this forumula public class DistanceAlgorithm ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |