将米转换为十进制度

时间:2014-08-11 06:53:45

标签: c# geo

我需要在C#中将米转换为十进制度数。我在Wikipedia上读到1小数等于111.32 km。但它在赤道上,所以如果我位于它上方/下方,我的转换将是错误的? 我认为这是错误的:

long sRad = (long.Parse(sRadTBx.Text)) / (111.32*1000); 

编辑:我需要此搜索范围来查找附近的用户

    long myLatitude = 100;
    long myLongitude = 100;
    long sRad = /* right formula to convert meters to decimal degrees*/

long begLat = myLatitude - searchRad;
long endLat = myLatitude + searchRad;
long begLong = myLongitude - searchRad;
long endLong = myLongitude + searchRad;

List<User> FoundUsers = new List<User>();

foreach (User user in db.Users)
{
    // Check if the user in the database is within range
    if (user.usrLat >= begLat && user.usrLat <= endLat && user.usrLong >= begLong && user.usrLong <= endLong)
    {
        // Add the user to the FoundUsers list
        FoundUsers.Add(user);
    }
}

1 个答案:

答案 0 :(得分:12)

同样来自维基百科的那篇文章:

 As one moves away from the equator towards a pole, however,
 one degree of longitude is multiplied by
 the cosine of the latitude,
 decreasing the distance, approaching zero at the pole.

所以这将是纬度的函数:

double GetSRad(double latitude)
{
    return 111.32 * Math.Cos(latitude * (Math.PI / 180));
}

或类似。

编辑:因此,为了反过来,将米转换为十进制度,你需要这样做:

double MetersToDecimalDegrees(double meters, double latitude)
{
    return meters / (111.32 * 1000 * Math.Cos(latitude * (Math.PI / 180)));
}