Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

calculate distance using latitude and longitude c#

public class Coordinates
{
    public double Latitude { get; private set; }
    public double Longitude { get; private set; }

    public Coordinates(double latitude, double longitude)
    {
        Latitude = latitude;
        Longitude = longitude;
    }
}
public static class CoordinatesDistanceExtensions
{
    public static double DistanceTo(this Coordinates baseCoordinates, Coordinates targetCoordinates)
    {
        return DistanceTo(baseCoordinates, targetCoordinates, UnitOfLength.Kilometers);
    }

    public static double DistanceTo(this Coordinates baseCoordinates, Coordinates targetCoordinates, UnitOfLength unitOfLength)
    {
        var baseRad = Math.PI * baseCoordinates.Latitude / 180;
        var targetRad = Math.PI * targetCoordinates.Latitude/ 180;
        var theta = baseCoordinates.Longitude - targetCoordinates.Longitude;
        var thetaRad = Math.PI * theta / 180;

        double dist =
            Math.Sin(baseRad) * Math.Sin(targetRad) + Math.Cos(baseRad) *
            Math.Cos(targetRad) * Math.Cos(thetaRad);
        dist = Math.Acos(dist);

        dist = dist * 180 / Math.PI;
        dist = dist * 60 * 1.1515;

        return unitOfLength.ConvertFromMiles(dist);
    }
}

public class UnitOfLength
{
    public static UnitOfLength Kilometers = new UnitOfLength(1.609344);
    public static UnitOfLength NauticalMiles = new UnitOfLength(0.8684);
    public static UnitOfLength Miles = new UnitOfLength(1);

    private readonly double _fromMilesFactor;

    private UnitOfLength(double fromMilesFactor)
    {
        _fromMilesFactor = fromMilesFactor;
    }

    public double ConvertFromMiles(double input)
    {
        return input*_fromMilesFactor;
    }
} 
Comment

calculate distance using latitude and longitude c#

var sCoord = new GeoCoordinate(sLatitude, sLongitude);
var eCoord = new GeoCoordinate(eLatitude, eLongitude);

return sCoord.GetDistanceTo(eCoord);
Comment

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;
}
Comment

distance between two points latitude longitude c#

float DeltaFi = (float)ConvertToRadians(lat2 - lat1);
float DeltaLambda = (float)ConvertToRadians(lon2 - lon1);
float a = Mathf.Sin(DeltaFi / 2) * Mathf.Sin(DeltaFi / 2) + Mathf.Cos(fi1) * Mathf.Cos(fi2) * Mathf.Sin(DeltaLambda / 2) * Mathf.Sin(DeltaLambda / 2);
float c = 2 * Mathf.Atan2(Mathf.Sqrt(a), Mathf.Sqrt(1 - a));
float distance = earthD * c;
Comment

formula calculating distance coordinates latitude longitude c#

lattitudelongitudecalculation
Comment

PREVIOUS NEXT
Code Example
Typescript :: matlab remove first n elements of array 
Typescript :: typescript type array of interface 
Typescript :: form reset typescript 
Typescript :: git status without untracked files 
Typescript :: typescript array of object with types 
Typescript :: Cannot show Automatic Strong Passwords for app bundleID: com.williamyeung.gameofchats due to error: iCloud Keychain is disabled 
Typescript :: failed to enumerate objects in the container access is denied windows 10 
Typescript :: init tsconfig file 
Typescript :: render async function to component 
Typescript :: how to add id in array javascript 
Typescript :: get random dark color 
Typescript :: typescript axios 
Typescript :: typescript trim spaces in string array 
Typescript :: how to add 2 bind events on one button tkinteer 
Typescript :: check if column exists in dataframe python 
Typescript :: how to sort a list of lists in python 
Typescript :: typescript type number range 
Typescript :: typescript treat all errors as warnings 
Typescript :: typescript pick type from interface 
Typescript :: Get Type of first element in Array TypeScript 
Typescript :: python discord action when someone reacts to message 
Typescript :: use sample weights fit model multiclass 
Typescript :: dota 2 space to center hero 
Typescript :: ng2-dnd not working with angular11 
Typescript :: typescript array 
Typescript :: O arquivo yarn.ps1 não pode ser carregado porque a execução de scripts foi desabilitada neste sistema 
Typescript :: ts date get minutes 
Typescript :: using typescript with vue 
Typescript :: run an applescript 
Typescript :: SafeValue must use [property]=binding: 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =