可以请求给定尺寸(米)的 bing 地图图像吗?
It is possible to request a bing map image from a given size ( meters )?
您好,我正在开发一款基于 BING 地图生成的游戏。
问题是:卡片是根据用户给的地址生成的,之后我想生成一张1km2的卡片(1000m宽1000m长)。
不幸的是,我找不到 bing API 来检索以米为单位定义大小的地图。我只能定义一个"level zoom"和一个分辨率
下面是我现在使用的(来自微软BingApiTile代码库示例):
// 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 米/像素的地图。您认为我的问题存在解决方案吗?
如果是的话我真的希望如此^^ :-)
好的,是的,这是可能的!!我花时间做一个函数,最后我自己解决了。但我很震惊,从来没有人问过这个问题,而且 Microsoft 也从来没有 post 的代码。我觉得这个功能真的很有用。
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);
}
您好,我正在开发一款基于 BING 地图生成的游戏。
问题是:卡片是根据用户给的地址生成的,之后我想生成一张1km2的卡片(1000m宽1000m长)。
不幸的是,我找不到 bing API 来检索以米为单位定义大小的地图。我只能定义一个"level zoom"和一个分辨率
下面是我现在使用的(来自微软BingApiTile代码库示例):
// 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 米/像素的地图。您认为我的问题存在解决方案吗?
如果是的话我真的希望如此^^ :-)
好的,是的,这是可能的!!我花时间做一个函数,最后我自己解决了。但我很震惊,从来没有人问过这个问题,而且 Microsoft 也从来没有 post 的代码。我觉得这个功能真的很有用。
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);
}