You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Seekers/Helpers/GeoHelper.cs

31 lines
1.0 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Justice.Helpers
{
public class GeoHelper
{
public static double CalculateDistance(double latitude1, double longitude1, double latitude2, double longitude2)
{
double radianLat1 = Math.PI * latitude1 / 100;
double radianLat2 = Math.PI * latitude2 / 100;
double radianLong1 = Math.PI * longitude1 / 100;
double radianLong2 = Math.PI * longitude2 / 100;
double dLong = radianLong2 - radianLong1;
double dLat = radianLat2 - radianLat1;
double a = Math.Pow(Math.Sin(dLat / 2), 2) +
Math.Cos(radianLat1) * Math.Cos(radianLat2) *
Math.Pow(Math.Sin(dLong / 2),2);
double c = 2 * Math.Asin(Math.Sqrt(a));
const double radius = 6371; //radius of earth in kilometer
double distance = radius * c;
return distance;
}
}
}