【问题标题】:How to calculate a new lat long based on distance from a point如何根据与点的距离计算新的经纬度
【发布时间】:2013-09-11 18:12:31
【问题描述】:

我正在尝试根据与该点的距离(以米为单位)计算该点的新纬度。

我在这里和其他地方发现了一些有用的帖子,但我仍然遇到了一些麻烦。

这是我目前得到的代码:

        public LatLon CalculateNewCoords(decimal startingLat, decimal startingLon, int distanceEast, int distanceNorth)
    {
        int r = 6378137;
        decimal dLat = Convert.ToDecimal(distanceNorth) / Convert.ToDecimal(r);

        decimal pi = Convert.ToDecimal(Math.PI);
        double cosInput = Convert.ToDouble(pi * startingLat / Convert.ToDecimal(180));

        decimal dLon = Convert.ToDecimal(distanceEast) / Convert.ToDecimal(Convert.ToDouble(r) * Math.Cos(cosInput));

        decimal lat0 = startingLat + dLat * (180 * pi);
        decimal lon0 = startingLon + dLon * (180 / pi);     

        LatLon output = new LatLon();
        output.Latitude = lat0;
        output.Longitude = lon0;

        return output;
    }

经度似乎是正确的,但纬度显示得非常明显。

我是这样使用的:

CalculateNewCoords(Convert.ToDecimal(40.743461), Convert.ToDecimal(-74.175847), 0, 1000);

谁能指出我做错了什么?

【问题讨论】:

    标签: c# map latitude-longitude


    【解决方案1】:

    错误在第一行:

        decimal lat0 = startingLat + dLat * (180 * pi);
        decimal lon0 = startingLon + dLon * (180 / pi);     
    

    这肯定是不正确的,两条线必须使用相同的弧度到度数的转换。 替换为第 2 行中的 180/pi。
    进一步考虑使用双精度而不是十进制。

    【讨论】:

    • 更准确地说,它们都应该是180 / pi
    • 对不起,我不太清楚你的意思。 edit 刚看到评论,谢谢。试过了,它就像一个魅力:)
    • 十进制比双倍好得多。
    • 你为什么这么认为?肯定不是,看不可读的代码,即使是浮点数就足够了
    • 只是想跳到这里。精度对我来说非常重要。我需要找到另一个点 10 米内的所有其他点,所以我越精确越好。至于不可读的代码,我会清理它,我只是在努力弄清楚出了什么问题:P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 2012-10-13
    • 2012-01-26
    • 2016-03-15
    • 2012-07-07
    相关资源
    最近更新 更多