gpt4 book ai didi

coordinates - 通过距离和方位从已知位置查找点坐标的地理算法

转载 作者:行者123 更新时间:2023-12-01 12:01:43 24 4
gpt4 key购买 nike

我想使用 Google map 静态 API 来显示带有指示边界的路径叠加层的 map 。

AFAICT 静态 API 不支持多边形,所以我打算通过使用路径绘制边界来规避这一点。

为此,我需要确定要在其间绘制直线(路径)的点;所以我想要一个算法来返回地理位置(即 WGS84 坐标)给定的方位角和距已知点的距离。

谁能告诉我这样的算法。最好使用 C#,但也可以使用其他语言?

最佳答案

我在 C# 中实现并测试了它,使用度数而不是弧度作为输入/输出:

    static readonly double FullCircleDegrees = 360d;
static readonly double HalfCircleDegrees = FullCircleDegrees / 2d;
static readonly double DegreesToRadians = Math.PI / HalfCircleDegrees;
static readonly double RadiansToDegrees = 1 / DegreesToRadians;

public LatLng GetPointGivenRadialAndDistance(LatLng center, double radius, double azimuth)
{
var lat1 = center.Lat * DegreesToRadians;
var lng1 = center.Lng * DegreesToRadians;
var lat = Math.Asin( (Math.Sin(lat1) * Math.Cos(radius)) + Math.Cos(lat1) * Math.Sin(radius) * Math.Cos(azimuth * DegreesToRadians));
var lng = 0d;
if (Math.Cos(lat) == 0)
{
lng = lng1;
}
else
{
lng = ((lng1 + Math.PI - Math.Asin(Math.Sin(azimuth * DegreesToRadians) * Math.Sin(radius) / Math.Cos(lat1))) % (2 * Math.PI)) - Math.PI;
}
return new LatLng(lat * RadiansToDegrees, lng * RadiansToDegrees);
}

关于coordinates - 通过距离和方位从已知位置查找点坐标的地理算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/695065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com