Abi*_*tro 4 c# geometry polygon
我正在尝试在地球表面上的给定点周围绘制一个正方形。
// Converting degrees to radians
double latInDecimals = (Math.PI / 180) * latitude;
double longInDecimals = (Math.PI / 180) * longitude;
List<string> lstStrCoords = new List<string>();
double changeInLat;
double changeInLong;
double lineOfLat;
// Calculating change in latitude for square of side
changeInLong = (side / 1000) * (360.0 / 40075);
// Calculating length of longitude at that point of latitude
lineOfLat = Math.Cos(longitude) * 40075;
// Calculating change in longitude for square of side 'side'
changeInLat = (side / 1000) * (360.0 / lineOfLat);
// Converting changes into radians
changeInLat = changeInLat * (Math.PI / 180);
changeInLong = changeInLong * (Math.PI / 180);
double nLat = changeInLat * (Math.Sqrt(2) / 2);
double nLong = changeInLong * (Math.Sqrt(2) / 2);
double coordLat1 = latInDecimals + nLat;
double coordLong1 = longInDecimals + nLong;
double coordLat2 = latInDecimals + nLat;
double coordLong2 = longInDecimals - nLong;
double coordLat3 = latInDecimals - nLat;
double coordLong3 = longInDecimals - nLong;
double coordLat4 = latInDecimals - nLat;
double coordLong4 = longInDecimals + nLong;
// Converting coords back to degrees
coordLat1 = coordLat1 * (180 / Math.PI);
coordLat2 = coordLat2 * (180 / Math.PI);
coordLat3 = coordLat3 * (180 / Math.PI);
coordLat4 = coordLat4 * (180 / Math.PI);
coordLong1 = coordLong1 * (180 / Math.PI);
coordLong2 = coordLong2 * (180 / Math.PI);
coordLong3 = coordLong3 * (180 / Math.PI);
coordLong4 = coordLong4 * (180 / Math.PI);
Run Code Online (Sandbox Code Playgroud)
现在即使这行得通,但我从加入这些多边形得到的多边形是一个矩形。

我对我的代码有什么问题感到困惑。
球体上经度和纬度为1的矩形的长度(以千米为单位)必须相同,除非它位于赤道上。它朝两极变窄。如果要使两边大小相同,则必须进行校正
longitudinal_length = latitudinal_length / cos(latitude)
Run Code Online (Sandbox Code Playgroud)
因此,您需要将正方形的纵向长度除以cos(latitude)。
现在,您的正方形可能仍会弯曲,但这取决于地图的投影方式,而这是一个完全不同的故事。您需要知道Google用来更正的投影公式。
您可能会发现更复杂的公式,其中考虑到地球不是一个完美的球体这一事实,但是我认为这对于您的位置标记应该足够了。还要注意,您将在+/- 90度处得到零除。因此在杆子上放置矩形需要另一种方法。

来自:IBM知识中心 / 地理坐标系 /图4.网格位置之间的不同尺寸