【发布时间】:2011-05-09 01:37:21
【问题描述】:
我一直在使用 Moveable-Type 网站来帮助我进行一些地理坐标计算,它非常有用,但是,我在计算两个坐标之间的中点时遇到了错误。我的结果接近预期,但还不够接近:
posA = {47.64570362, -122.14073746}
posB = {47.64316917, -122.14032175}
预期结果(取自活字计算器)= 47°38′40″N,122°08′26″W = {47.644444, -122.140556}我的结果:{49.6054801645915, -122.14052959995759}
这是我的代码:
private Geocoordinate MidPoint(Geocoordinate posA, Geocoordinate posB)
{
Geocoordinate midPoint = new Geocoordinate();
double dLon = DegreesToRadians(posB.Longitude - posA.Longitude);
double Bx = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Cos(dLon);
double By = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Sin(dLon);
midPoint.Latitude = RadiansToDegrees(Math.Atan2(Math.Sin(DegreesToRadians(posA.Latitude)) + Math.Sin(DegreesToRadians(posB.Latitude)),
Math.Sqrt((Math.Cos(DegreesToRadians(posA.Latitude)) + Bx) * (Math.Cos(DegreesToRadians(posA.Latitude))) + Bx) + By * By));
midPoint.Longitude = posA.Longitude + RadiansToDegrees(Math.Atan2(By, Math.Cos(DegreesToRadians(posA.Latitude)) + Bx));
return midPoint;
}
我有几个私有方法可以在度数和弧度之间进行转换并返回。 例如
private double DegreeToRadian(double angle)
{
return Math.PI * angle / 180.0;
}
我无法弄清楚为什么我的结果与 Lat 值相差几度。有什么想法吗?
谢谢
【问题讨论】:
-
偏离我的整体度(你期望
34.8954但得到29.8954)或近似(你期望34.8954但得到@987654330 @)? -
我不太确定您将地球表面视为简单球体还是椭球体。上次我使用兰伯特定律 [使用 Java 实现] 工作时,它似乎工作正常。
-
谢谢。它在纬度上偏离了 2 度,而经度几乎是正确的。我在这个网站上用的是中点计算公式,翻译成C#movable-type.co.uk/scripts/latlong.html
-
我讨厌触发...谢谢!
标签: c# geolocation latitude-longitude