我需要根据指定的距离找到纬度和经度。例如,我说的距离为50厘米,并且有一个纬度和经度点,我想找到距第一点50厘米远的下一个点是什么?
嘿,我得到了解决方案,我已经通过按照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);