我如何找到给定经纬度以北x公里的纬度/经度? [英] How do I find the lat/long that is x km north of a given lat/long?

查看:179
本文介绍了我如何找到给定经纬度以北x公里的纬度/经度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些生成谷歌地图的C#代码。此代码查看我需要在地图上绘制的所有点,然后计算矩形的边界以包含这些点。然后它将这个界限传递给Google Maps API,以适当地设置缩放级别,以显示地图上的所有点。



这段代码工作正常,但我有一个新的要求。

其中一点可能有与之相关的精确度。如果是这种情况,那么我围绕半径设置为精度值的点绘制一个圆。再次,这工作正常但是我的边界检查现在没有做我想做的事情。我希望边界框包含完整的圆。



这需要一个算法来计算点x,并计算y点在x以北z米处,也就是z的南部。



有没有人有这种算法,最好在C#中。我确实在这里找到了一个通用算法,但是我似乎没有正确实现这个答案我得到的是1000公里漂流。



这是通用的例子

  Lat / lon给定径向距离

如果满足以下条件,点{lat,lon}是从点1开始的tc径向距离d out:

lat = asin sin(lat1)* cos(d)+ cos(lat1)* sin(d)* cos(tc))
IF(cos(lat)= 0)
lon = lon1 // end a pole
ELSE
lon = mod(lon1-asin(sin(tc)* sin(d)/ cos(lat))+ pi,2 * pi)-pi
ENDIF

这是我的C#翻译。

  //以指定的距离扩展一个点North / South 
public static Point ExtendPoint(Point _pt,int _distance ,int _bearing)
{
Decimal lat = 0.0;
十进制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; //终点a
}
else
{
lng =(
(_pt.Lng - Math.Asin(Math.Sin(_bearing)* Math.Sin (_distance)/ Math.Cos(lat))
+ Math.PI)%(2 * Math.PI)) - Math.PI;
}

ret =新点(lat,lng);
return ret;

$ / code>

我调用这个函数的方位为0来计算新的偏北位置和一个180的值来计算新的偏南位置。

任何人都可以看到我做错了什么,或者提供一个已知的工作算法吗?

解决方案

如果你有一个给定的纬度和经度,你可以计算纬度x-km变化的正确纬度和经度,如下所示:

  new-lat =((old-km-north + x-km-change)/ 40,075)* 360)
^是^乘以地球圈
的比例乘以360得到总比值
的比率。以度数覆盖。

同样适用于经度。如果你有总距离加上变化,你可以用类似的方式计算总度。

  new-long =((old-km-east + x-km-change)/ 40,075)* 360)
^是地球圈子
的比率乘以360得到总比率
的比率。以度数覆盖。

再一次,这些计算应该可以工作,但我在这里没有纯直觉,但逻辑确实似乎是成立的。

编辑:正如Skizz指出的,40,075需要在任何给定的纬度使用2.pi.r.cos调整到地球的周围(lat)或40074.cos(lat)

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.

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.

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.

This is the Generic example

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

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;
    }

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?

解决方案

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
           of the 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
           of the 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.

Edit: 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公里的纬度/经度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆