How do I find the lat/long that is x km north of a given lat/long?

前端 未结 7 1087
花落未央
花落未央 2020-11-30 03:48

I have some C# code that generates google maps. This codes looks at all the Points I need to plot on the map and then works out the Bounds of a rectangle to include those po

相关标签:
7条回答
  • 2020-11-30 04:44

    I have a very similar piece of code. It got me very close results when compared to another implementation.

    I think the problem with yours is that you are using "distance" as linear distance in meters instead of angular distance in radians.

    /// <summary>
    /// Calculates the end-point from a given source at a given range (meters) and bearing (degrees).
    /// This methods uses simple geometry equations to calculate the end-point.
    /// </summary>
    /// <param name="source">Point of origin</param>
    /// <param name="range">Range in meters</param>
    /// <param name="bearing">Bearing in degrees</param>
    /// <returns>End-point from the source given the desired range and bearing.</returns>
    public static LatLonAlt CalculateDerivedPosition(LatLonAlt source, double range, double bearing)
    {
        double latA = source.Latitude * UnitConstants.DegreesToRadians;
        double lonA = source.Longitude * UnitConstants.DegreesToRadians;
        double angularDistance = range / GeospatialConstants.EarthRadius;
        double trueCourse = bearing * UnitConstants.DegreesToRadians;
    
        double lat = Math.Asin(
            Math.Sin(latA) * Math.Cos(angularDistance) + 
            Math.Cos(latA) * Math.Sin(angularDistance) * Math.Cos(trueCourse));
    
        double dlon = Math.Atan2(
            Math.Sin(trueCourse) * Math.Sin(angularDistance) * Math.Cos(latA), 
            Math.Cos(angularDistance) - Math.Sin(latA) * Math.Sin(lat));
    
        double lon = ((lonA + dlon + Math.PI) % UnitConstants.TwoPi) - Math.PI;
    
        return new LatLonAlt(
            lat * UnitConstants.RadiansToDegrees, 
            lon * UnitConstants.RadiansToDegrees, 
            source.Altitude);
    }
    

    Where

    public const double EarthRadius = 6378137.0;   //  WGS-84 ellipsoid parameters
    

    and LatLonAlt is in degrees/meters (conversion takes place internally). Adjust as needed.

    I assume you can figure out what the value for UnitConstants.DegreesToRadians is :)

    0 讨论(0)
提交回复
热议问题