【发布时间】:2015-01-05 04:58:33
【问题描述】:
我正在使用 Bing 地图开发一个 Windows 应用商店应用程序 (C#)。
我希望能够在给定位置集合(纬度和经度对)的情况下,确定地图的缩放级别应该是什么,以及它的中心点(位置)应该是什么。
从位置值的集合中,我提取了需要显示的四个“极端”基点(最北、最南、最东和最西)。
IOW,如果我想在整个旧金山显示图钉,我想获得缩放级别以仅显示该城市,仅此而已。如果我想展示散布在美国各地的图钉,……你懂的。
这是我目前所拥有的(只是一个粗略的草稿/伪代码,如您所见):
确定一组位置的极端基数值(代码未显示;应该是微不足道的)。创建我的自定义类的实例:
public class GeoSpatialBoundaries
{
public double furthestNorth { get; set; }
public double furthestSouth { get; set; }
public double furthestWest { get; set; }
public double furthestEast { get; set; }
}
...然后调用这些方法,传递该实例:
// This seems easy enough, but perhaps my solution is over-simplistic
public static Location GetMapCenter(GeoSpatialBoundaries gsb)
{
double lat = (gsb.furthestNorth + gsb.furthestSouth) / 2;
double lon = (gsb.furthestWest + gsb.furthestEast) / 2;
return new Location(lat, lon);
}
// This math may be off; just showing my general approach
public static int GetZoomLevel(GeoSpatialBoundaries gsb)
{
double latitudeRange = gsb.furthestNorth - gsb.furthestSouth;
double longitudeRange = gsb.furthestEast - gsb.furthestWest;
int latZoom = GetZoomForLat(latitudeRange);
int longZoom = GetZoomForLong(longitudeRange);
return Math.Max(latZoom, longZoom);
}
不过,这才是我真正迷路的地方。如何根据这些 val 确定要返回的缩放级别(在 1..20 之间)?这里有个很粗略的思路(GetZoomForLat() 基本一样):
// Bing Zoom levels range from 1 (the whole earth) to 20 (the tippy-top of the cat's whiskers)
private static int GetZoomForLong(double longitudeRange)
{
// TODO: What Zoom level ranges should I set up as the cutoff points? IOW, should it be something like:
if (longitudeRange > 340) return 1;
else if (longitudeRange > 300) return 2;
// etc.? What should the cutoff points be?
else return 1;
}
有没有人有任何建议或链接可以告诉我如何实现这些功能?
【问题讨论】:
标签: c# geolocation bing-maps