如何根据距离和第一个纬度,经度点获取下一个纬度和经度位置?

时间:2020-03-07 09:45:28

标签: google-maps maps gmap.net

我需要根据指定的距离查找纬度和经度。例如,我说的距离是50厘米,并且有一个纬度和经度点,我想找到距我的第一个点50厘米远的下一个点是什么?

1 个答案:

答案 0 :(得分:1)

嘿,我得到了解决方案,我已经按照https://www.movable-type.co.uk/scripts/latlong.html的计算方法实现了该解决方案,并在c#中实现了该计算

    public static double DegreesToRadians(double degrees)
    {
        const double degToRadFactor = Math.PI / 180;
        return degrees * degToRadFactor;
    }

    public static double RadiansToDegrees(double radians)
    {
        const double radToDegFactor = 180 / Math.PI;
        return radians * radToDegFactor;
    }

   private double GetBearing(PointLatLng pt1, PointLatLng pt2)
    {
        double x = Math.Cos(DegreesToRadians(pt1.Lat)) *                Math.Sin(DegreesToRadians(pt2.Lat)) - Math.Sin(DegreesToRadians(pt1.Lat)) * Math.Cos(DegreesToRadians(pt2.Lat)) * Math.Cos(DegreesToRadians(pt2.Lng - pt1.Lng));
        double y = Math.Sin(DegreesToRadians(pt2.Lng - pt1.Lng)) * Math.Cos(DegreesToRadians(pt2.Lat));

        return (Math.Atan2(y, x) + Math.PI * 2) % (Math.PI * 2);            
    }


     public static PointLatLng FindPointAtDistanceFrom(PointLatLng startPoint, double initialBearingRadians)
    {
        double distanceKilometres = 0.0005; //50cm = 0.0005Km;
        const double radiusEarthKilometres = 6371.01;
        var distRatio = distanceKilometres / radiusEarthKilometres;
        var distRatioSine = Math.Sin(distRatio);
        var distRatioCosine = Math.Cos(distRatio);

        var startLatRad = DegreesToRadians(startPoint.Lat);
        var startLonRad = DegreesToRadians(startPoint.Lng);

        var startLatCos = Math.Cos(startLatRad);
        var startLatSin = Math.Sin(startLatRad);

        var endLatRads = Math.Asin((startLatSin * distRatioCosine) + (startLatCos * distRatioSine * Math.Cos(initialBearingRadians)));

        var endLonRads = startLonRad
            + Math.Atan2(
                Math.Sin(initialBearingRadians) * distRatioSine * startLatCos,
                distRatioCosine - startLatSin * Math.Sin(endLatRads));

        return new PointLatLng
        {
            Lat = RadiansToDegrees(endLatRads),
            Lng = RadiansToDegrees(endLonRads)
        };
    }

此代码的用法是:

    //Get Angle of point
    var bearing = GetBearing(polyStartPoint, polyEndPoint);
    //Get Point from 50cm away for specified point
    var nextStartPoint = FindPointAtDistanceFrom(polyStartPoint, bearing);