可以从给定的尺寸(米)请求bing地图图像吗?

时间:2015-07-27 11:12:37

标签: c# dictionary bing-maps bing bing-api

您好我正在开发一款基于BING地图生成的游戏。

问题是:卡是根据用户提供的地址生成的,之后我想生成1km2卡(1000米宽,1000米长)。

不幸的是,我发现没有bing API来检索定义大小(以米为单位)的地图。我只能定义一个"级别缩放"和决议。

这是我现在使用的(来自Microsoft Bing Api Tile代码库示例):

Bing Maps Tile System

// Get a bing Map (resolution max. 834 pixel) with zoom level 16
var stream = await httpClient.GetStreamAsync("api/newmap/?latitude=46.6052284&longitude=7.0967002&mapSizeHeight=834&mapSizeWidth=834&zoomLevel=16");
    // Calculated from "latitudeCentre" and "zoom level" , i get like 0.8 meter/pixel
double meterPerPixel = TileSystem.GroundResolution(latitudeCentre, 16);

例如(834/834像素)和缩放级别16 =>这给了我一个0.8米/像素的比例。我无法生成1米/像素的地图。您认为我的问题的解决方案存在吗?

我真的希望如果是的话^^ :-)

1 个答案:

答案 0 :(得分:1)

好的,是的,这是可能的!我需要时间来制作一个功能,最后我自己解决它。但我感到震惊,没有人从未问过这个问题,而微软从未发布过该代码。我认为这个功能非常有用。

private void SetBoundingBoxLocationAndZoom(double latitudeCentre)
    {
        // 1024/1024 meters
        double desiredMapSize = 1024.0;


        int bestMatchMapSize = 0;
        int bestMatchMapResolution = 0;
        int bestMatchMapZoom = 0;



        //Starts with the largest zoom and ending with the smallest (remote) (min zoomLevel [1])
        // 1 - 21
        for (int zoom = 21; zoom >= 1; zoom--)
        {

            //Starts with the highest resolution and ending with the smallest (min pixel 80/80)
            // 80 - 834
            for (int resolution = 834; resolution >= 80; resolution--)
            {
                double meterPerPixel = TileSystem.GroundResolution(latitudeCentre, zoom);
                double mapSize = meterPerPixel * resolution;

                if(Math.Abs(desiredMapSize - mapSize) < Math.Abs(desiredMapSize - bestMatchMapSize))
                {
                    bestMatchMapSize = (int)mapSize;
                    bestMatchMapResolution = resolution;
                    bestMatchMapZoom = zoom;
                }
            }
        }


        zoomLevel = bestMatchMapZoom;
        sizeMapInMeter = bestMatchMapSize;
        resolutionMap = bestMatchMapResolution;



    }

    /// <summary>
        /// Determines the ground resolution (in meters per pixel) at a specified
        /// latitude and level of detail.
        /// </summary>
        /// <param name="latitude">Latitude (in degrees) at which to measure the
        /// ground resolution.</param>
        /// <param name="levelOfDetail">Level of detail, from 1 (lowest detail)
        /// to 23 (highest detail).</param>
        /// <returns>The ground resolution, in meters per pixel.</returns>
        public static double GroundResolution(double latitude, int levelOfDetail)
        {
            latitude = Clip(latitude, MinLatitude, MaxLatitude);
            return Math.Cos(latitude * Math.PI / 180) * 2 * Math.PI * EarthRadius / MapSize(levelOfDetail);
        }