google-mapsmapsgmap.net

How to get next latitude and longtitude position acording to distance and first latitude, longtitude point?


I need to find latitude and longtitude according to distance specified. For example I have distance say 50centimeter and one latitude and longtitude point and I want to find what is the next point which is far from 50cm from my first point?


Solution

  • Hey I got the solution and I have implemented this by following calculation from https://www.movable-type.co.uk/scripts/latlong.html and implemented this calculation in 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)
            };
        }
    

    And Usage of this code is:

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