簡體   English   中英

如何在沒有JavaScript的情況下計算地圖范圍

[英]How to calculate map bounds without javascript

我有一個坐標列表,該列表將被視為地圖的中心點。

我只需要使用C#(沒有javascript沒有地圖對象)來計算縮放級別16的地圖邊界。

這可能嗎?

請指教。

這是我想要的東西。 我還沒有寫過這堂課,所以在這里找到了。 提供的緯度和經度以及以KM為單位的半徑將提供一個邊界框。 GMap在視口邊界上提供了一些功能。

            public class GlobalMercator
            {
                public class MapPoint
                {
                    public double Longitude { get; set; } // In Degrees
                    public double Latitude { get; set; } // In Degrees
                }

                public class BoundingBox
                {
                    public MapPoint MinPoint { get; set; }
                    public MapPoint MaxPoint { get; set; }
                }

                // Semi-axes of WGS-84 geoidal reference
                private const double WGS84_a = 6378137.0; // Major semiaxis [m]
                private const double WGS84_b = 6356752.3; // Minor semiaxis [m]

                // 'halfSideInKm' is the half length of the bounding box you want in kilometers.
                public static BoundingBox GetBoundingBox(MapPoint point, double halfSideInKm)
                {
                    // Bounding box surrounding the point at given coordinates,
                    // assuming local approximation of Earth surface as a sphere
                    // of radius given by WGS84
                    var lat = Deg2rad(point.Latitude);
                    var lon = Deg2rad(point.Longitude);
                    var halfSide = 1000 * halfSideInKm;

                    // Radius of Earth at given latitude
                    var radius = WGS84EarthRadius(lat);
                    // Radius of the parallel at given latitude
                    var pradius = radius * Math.Cos(lat);

                    var latMin = lat - halfSide / radius;
                    var latMax = lat + halfSide / radius;
                    var lonMin = lon - halfSide / pradius;
                    var lonMax = lon + halfSide / pradius;

                    return new BoundingBox
                    {
                        MinPoint = new MapPoint { Latitude = Rad2deg(latMin), Longitude = Rad2deg(lonMin) },
                        MaxPoint = new MapPoint { Latitude = Rad2deg(latMax), Longitude = Rad2deg(lonMax) }
                    };
                }

                // degrees to radians
                private static double Deg2rad(double degrees)
                {
                    return Math.PI * degrees / 180.0;
                }

                // radians to degrees
                private static double Rad2deg(double radians)
                {
                    return 180.0 * radians / Math.PI;
                }

                // Earth radius at a given latitude, according to the WGS-84 ellipsoid [m]
                private static double WGS84EarthRadius(double lat)
                {
                    // http://en.wikipedia.org/wiki/Earth_radius
                    var An = WGS84_a * WGS84_a * Math.Cos(lat);
                    var Bn = WGS84_b * WGS84_b * Math.Sin(lat);
                    var Ad = WGS84_a * Math.Cos(lat);
                    var Bd = WGS84_b * Math.Sin(lat);
                    return Math.Sqrt((An * An + Bn * Bn) / (Ad * Ad + Bd * Bd));
                }  
            }   

暫無
暫無

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

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