calculate distance using latitude and longitude c#
var sCoord = new GeoCoordinate(sLatitude, sLongitude);
var eCoord = new GeoCoordinate(eLatitude, eLongitude);
return sCoord.GetDistanceTo(eCoord);
calculate distance using latitude and longitude c#
var sCoord = new GeoCoordinate(sLatitude, sLongitude);
var eCoord = new GeoCoordinate(eLatitude, eLongitude);
return sCoord.GetDistanceTo(eCoord);
calculate distance using latitude and longitude c#
public static double DistanceTo(double lat1, double lon1, double lat2, double lon2, char unit = 'K')
{
double rlat1 = Math.PI*lat1/180;
double rlat2 = Math.PI*lat2/180;
double theta = lon1 - lon2;
double rtheta = Math.PI*theta/180;
double dist =
Math.Sin(rlat1)*Math.Sin(rlat2) + Math.Cos(rlat1)*
Math.Cos(rlat2)*Math.Cos(rtheta);
dist = Math.Acos(dist);
dist = dist*180/Math.PI;
dist = dist*60*1.1515;
switch (unit)
{
case 'K': //Kilometers -> default
return dist*1.609344;
case 'N': //Nautical Miles
return dist*0.8684;
case 'M': //Miles
return dist;
}
return dist;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us