簡體   English   中英

圍繞一個長點畫一個正方形

[英]Drawing a square around a lat-long point

我試圖在地球表面的某個點周圍畫一個正方形

我正在使用從這里這里檢索到的信息,最終得出了這個: -

        // 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);

現在即使這樣,我加入的多邊形也是一個矩形。

在此輸入圖像描述

我對我的代碼有什么問題感到困惑。

除非球座位於赤道上,否則球體上一個緯度和經度的矩形長度不同於km。 它朝着兩極走得更窄。 如果你想讓雙面都相同,你必須進行修正

longitudinal_length = latitudinal_length / cos(latitude)

因此,您需要將您的平方縱向長度除以cos(latitude)

現在,您的廣場可能仍然是彎曲的,但這取決於地圖的投影方式,這是一個完全不同的故事。 您需要知道Google使用的投影公式進行更正。

您可能會發現更復雜的公式,考慮到地球不是一個完美的球體這一事實,但我認為這應該足以滿足您的位置標記。 另請注意,您將在+/- 90度處獲得零除。 因此,在桿上放置一個矩形需要另一種方法。

在此輸入圖像描述
來自: IBM知識中心 / 地理坐標系 /圖4.經緯網上位置之間的不同尺寸

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM