我有一些生成谷歌地图的 C# 代码.此代码查看我需要在地图上绘制的所有点,然后计算出矩形的边界以包含这些点.然后它将此边界传递给 Google Maps API 以适当地设置缩放级别以显示地图上的所有点.
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 points. It then passes this bounds to the Google Maps API to set the zoom level appropriately to show all of the points on the map.
此代码运行良好,但我有一个新要求.
This code is working fine however I have a new requirement.
其中一个点可能具有与之相关的精度.如果是这种情况,那么我在该点周围画一个圆,半径设置为精度值.这再次工作正常,但是我的边界检查现在没有做我想要做的事情.我想让边界框包含完整的圆圈.
One of the points may have a precision associated with it. If this is the case then I draw a circle around the point with the radius set to the precision value. Again this works fine however my bounds checking is now not doing what I want it to do. I want to have the bounding box include the complete circle.
这需要一种算法来获取点 x 并计算点 y,该点位于 x 以北 z 米处和 x 以南 z 米处.
This requires an algorithm to take a point x and calculate the point y that would be z metres north of x and also z metres south of x.
有没有人有这个算法,最好是在 C# 中.我确实找到了一个通用算法 here 但我似乎没有正确实现这个作为我的答案得到的是 1000 公里的漂移.
Does anyone have this algorithm, preferably in C#. I did find a generic algorithm here but I appear to have not implemented this correctly as the answers I am getting are 1000s of km adrift.
这是通用示例
Lat/lon given radial and distance
A point {lat,lon} is a distance d out on the tc radial from point 1 if:
lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
IF (cos(lat)=0)
lon=lon1 // endpoint a pole
ELSE
lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
ENDIF
这是我的 C# 翻译.
And this is my C# translation.
// Extend a Point North/South by the specified distance
public static Point ExtendPoint(Point _pt, int _distance, int _bearing )
{
Decimal lat = 0.0;
Decimal lng = 0.0;
lat = Math.Asin(Math.Sin(_pt.Lat) * Math.Cos(_distance) + Math.Cos(_pt.Lat) *
Math.Sin(_distance) * Math.Cos(_bearing));
if (Math.Cos(lat) == 0)
{
lng = _pt.Lng; // endpoint a pole
}
else
{
lng = (
(_pt.Lng - Math.Asin(Math.Sin(_bearing) * Math.Sin(_distance) / Math.Cos(lat))
+ Math.PI) % (2 * Math.PI)) - Math.PI;
}
ret = new Point(lat,lng);
return ret;
}
我调用这个函数的方位角为 0 来计算新的北纬位置,值 180 来计算新的南纬位置.
I am calling this function with a bearing of 0 to calculate the new northerly position and a value of 180 to calculate the new southerly position.
谁能看到我做错了什么或者提供一个已知的工作算法?
Can anyone either see what I have done wrong or perhaps provide a known working algorithm?
如果你有一个给定的纬度和经度,你可以像这样计算 x-km 纬度变化的正确纬度和经度:
If you have a given latitude and longitude you can calculate the correct latitude and longitude of an x-km change in latitude like so:
new-lat = ((old-km-north + x-km-change)/40,075) * 360)
^ is the ratio of the ^ times the ratio of the circle
earth the change by 360 to get the total ratio
covers. covered in degrees.
这同样适用于经度.如果你有总距离加上变化,你可以用类似的方式计算总度数.
The same can apply to longitude. If you have the total distance plus the change you can calculate the total degrees in a similar fashion.
new-long = ((old-km-east + x-km-change)/40,075) * 360)
^ is the ratio of the ^ times the ratio of the circle
earth the change by 360 to get the total ratio
covers. covered in degrees.
同样,这些计算应该有效,但我在这里失去了纯粹的直觉,但逻辑似乎确实成立.
Again, these calculations should work, but I'm running off pure intuition here, but the logic does seem to hold true.
正如 Skizz 所指出的,需要使用 2.pi.r.cos(lat) 或 40074.cos(lat) 将 40,075 调整到任何给定纬度的地球圆周
As pointed out by Skizz 40,075 needs to be adjusted to the circumference of the earth at any given latitude using 2.pi.r.cos(lat) or 40074.cos(lat)
这篇关于如何找到给定纬度/经度以北 x 公里的纬度/经度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!