How do I calculate the Azimuth (angle to north) between two WGS84 coordinates

后端 未结 6 2120
被撕碎了的回忆
被撕碎了的回忆 2020-12-25 09:52

I have got two WGS84 coordinates, latitude and longitude in degrees. These points are rather close together, e.g. only one metre apart.

Is there an easy way to calcu

6条回答
  •  一生所求
    2020-12-25 10:20

    Here is the C# solution. Tested for 0, 45, 90, 135, 180, 225, 270 and 315 angles.

    Edit I replaced my previous ugly solution, by the C# translation of Wouter's solution:

    public double GetAzimuth(LatLng destination)
    {
        var longitudinalDifference = destination.Lng - this.Lng;
        var latitudinalDifference = destination.Lat - this.Lat;
        var azimuth = (Math.PI * .5d) - Math.Atan(latitudinalDifference / longitudinalDifference);
        if (longitudinalDifference > 0) return azimuth;
        else if (longitudinalDifference < 0) return azimuth + Math.PI;
        else if (latitudinalDifference < 0) return Math.PI;
        return 0d;
    }
    
    public double GetDegreesAzimuth(LatLng destination)
    {
        return RadiansToDegreesConversionFactor * GetAzimuth(destination);
    }
    

提交回复
热议问题