当前位置: 首页 > 编程语言 > C#

两个坐标之间的地理中点共享

时间:2023-04-11 01:00:20 C#

两个坐标之间的地理中点计算两个坐标之间的中点时出现错误。我的结果接近预期,但不够接近: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}这是我的代码:privateGeocoordinateMidPoint(GeocoordinateposA,GeocoordinateposB){GeocoordinatemidPoint=newGeocoordinateDegrees=();doubledLons.Longitude-posA.Longitude);doubleBx=Math.Cos(DegreesToRadians(posB.Latitude))*Math.Cos(dLon);doubleBy=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));返回中点;我有几个私有方法在度数和弧度之间进行转换,例如privatedoubleDegreeToRadian(doubleangle){returnMath.PI*angle/180.0;我不明白为什么我的结果在Lat值上有几度的偏差。有任何想法吗?谢谢你有一些括号错误。我在代码中标记了这个位置。privateGeocoordinateMidPoint(GeocoordinateposA,GeocoordinateposB){GeocoordinatemidPoint=newGeocoordinate();双dLon=DegreesToRadians(posB.Longitude-posA.Longitude);双Bx=Math.Cos(DegreesToRadians(posB.Latitude))*Math.Cos(dLon);doubleBy=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)));//(Math.Cos(DegreesToRadians(posA.Latitude)))+Bx)+By*By));//你的代码midPoint.Longitude=posA.Longitude+RadiansToDegrees(Math.Atan2(By,Math.Cos(DegreesToRadians(posA.Latitude))+Bx));返回中点;}一些方法(例如WGS84惯例)包含地球的抑制率。(至少这里是这么说的)以上就是《C#学习教程:两个坐标之间的地理中点》分享的全部内容,如果对大家有用,需要进一步了解C#学习教程,希望大家喜欢it注意——本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: