大距离获取不正确的纬度和经度

本文关键字:纬度 经度 不正确 距离 获取 | 更新日期: 2023-09-27 17:59:28

我正在使用以下函数。

    private static Location CoordinateAtADistance(double latOrigin, double lonOrigin, double radius, double angle)
    {
        double lonDestination;
        double R = 6371.0;
        double d = radius / R;  // d = angular distance covered on earth's surface
        double lat1 = ToRadian(latOrigin);
        double lon1 = ToRadian(lonOrigin);
        double brng = ToRadian(angle);

        double latDestination = lat1 + d * Math.Cos(brng);
        double dLat = d * Math.Cos(brng);
        double dPhi = Math.Log(Math.Tan(latDestination / 2 + Math.PI / 4) / Math.Tan(lat1 / 2 + Math.PI / 4));
        double q = (double.IsNaN(dLat / dPhi)) ? dLat / dPhi : Math.Cos(lat1);  // E-W line gives dPhi=0
        double dLon = d * Math.Sin(brng) / q;
        // check for some daft bugger going past the pole
        if (Math.Abs(latDestination) > Math.PI / 2)
            latDestination = latDestination > 0 ? Math.PI - latDestination : -(Math.PI - latDestination);
        lonDestination = (lon1 + dLon +3* Math.PI) % (2 * Math.PI) - Math.PI;
        Location nextPoint = new Location();
        if (angle == 0)
        {
            nextPoint.Latitude = ToDegree(latDestination);
            nextPoint.Longitude = lonOrigin;
        }
        if (angle == 90)
        {
            nextPoint.Latitude = latOrigin;
            nextPoint.Longitude = ToDegree(lonDestination);
        }
        return nextPoint;
    }

这里的半径是距离。

现在的问题是,当我计算短距离时,例如几百公里,它可以完美地工作。但对于大距离,比如11000公里的正确经度。请不要这样,我只沿着纬度或经度移动,所以其中一个无论如何都不会改变。当移动到纬度时,我得到了正确的答案,但对于经度的值并没有更接近。如果有什么不清楚的地方,请发表评论。

大距离获取不正确的纬度和经度

    double latDestination = lat1 + d * Math.Cos(brng);
        double dLat = d * Math.Cos(brng);
        double dPhi = Math.Log(Math.Tan(latDestination / 2 + Math.PI / 4) / Math.Tan(lat1 / 2 + Math.PI / 4));
        double q = (double.IsNaN(dLat / dPhi)) ? dLat / dPhi : Math.Cos(lat1);  // E-W line gives dPhi=0
        double dLon = d * Math.Sin(brng) / q;
        // check for some daft bugger going past the pole
        if (Math.Abs(latDestination) > Math.PI / 2)
            latDestination = latDestination > 0 ? Math.PI - latDestination : -(Math.PI - latDestination);
        lonDestination = (lon1 + dLon + 3 * Math.PI) % (2 * Math.PI) - Math.PI;

需要进行一点修正,上面的公式运行良好。