■ 거리 구하기

------------------------------------------------------------------------------------------------------------------------

using System;

 

#region 거리 구하기 - GetDistance(latitude1, longitude1, latitude2, longitud2, unit)

 

/// <summary>

/// 거리 구하기

/// </summary>

/// <param name="latitude1">위도 1</param>

/// <param name="longitude1">경도 1</param>

/// <param name="latitude2">위도 2</param>

/// <param name="longitud2">경고 2</param>

/// <param name="unit">단위</param>

/// <returns>거리</returns>

public double GetDistance(double latitude1, double longitude1, double latitude2, double longitud2, char unit)

{

    double theta;

    double distance;

 

    theta = longitude1 - longitud2;

 

    distance = Math.Sin(GetRadian(latitude1)) * Math.Sin(GetRadian(latitude2)) +

               Math.Cos(GetRadian(latitude1)) * Math.Cos(GetRadian(latitude2)) * Math.Cos(GetRadian(theta));

 

    distance = Math.Acos(distance);

 

    distance = GetDegree(distance);

 

    distance = distance * 60 * 1.1515;

 

    switch(unit)

    {

        // Statute mile : 법정 마일(약 1,609km)

        case 'm' :

        case 'M' : break;

 

        // 킬로미터

        case 'k' :

        case 'K' : distance = distance * 1.609344; break;

 

        // Nautical mile : 해리(1,852미터)

        case 'n' :

        case 'N' : distance = distance * 0.8684; break;

    }

 

    return distance;

}

 

#endregion

#region 라디안 구하기 - GetRadian(degree)

 

/// <summary>

/// 라디안 구하기

/// </summary>

/// <param name="degree"></param>

/// <returns>라디안</returns>

private double GetRadian(double degree)

{

    return (degree * Math.PI / 180);

}

 

#endregion

#region 도 구하기 - GetDegree(radian)

 

/// <summary>

/// 도 구하기

/// </summary>

/// <param name="radian">라디안</param>

/// <returns></returns>

private double GetDegree(double radian)

{

    return (radian * 180 / Math.PI);

}

 

#endregion

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG