Asp.net mvc 虚拟地球/必应地图-如何计算最佳缩放级别

Asp.net mvc 虚拟地球/必应地图-如何计算最佳缩放级别,asp.net-mvc,bing-maps,virtual-earth,Asp.net Mvc,Bing Maps,Virtual Earth,我正在做一些地图的东西,我被一些看起来很基本的东西卡住了 我所做的主要工作是向地图添加10个标志,我需要根据图钉的位置动态设置地图的缩放级别和中心(地图需要在显示所有图钉的同时尽可能放大) 在没有任何干预的情况下,MultiMap的工作原理与预期完全相同(如预期的那样),但虚拟地球地图的效果并不好。如果我不给它一个中心Lat/Lon,它默认显示所有的美国 有人能给我指出正确的方向,让这项工作顺利进行吗 编辑: 好的,我可以通过在我的MVC控制器中使用以下命令来计算正确的中心 ''# we're

我正在做一些地图的东西,我被一些看起来很基本的东西卡住了

我所做的主要工作是向地图添加10个标志,我需要根据图钉的位置动态设置地图的缩放级别和中心(地图需要在显示所有图钉的同时尽可能放大)

在没有任何干预的情况下,MultiMap的工作原理与预期完全相同(如预期的那样),但虚拟地球地图的效果并不好。如果我不给它一个中心Lat/Lon,它默认显示所有的美国

有人能给我指出正确的方向,让这项工作顺利进行吗

编辑: 好的,我可以通过在我的MVC控制器中使用以下命令来计算正确的中心

''# we're going to rock the AVERAGE LAT/LON here
Dim eventCount As Integer = 0
Dim totalLat As Double = 0
Dim totalLon As Double = 0
For Each mel In MapEventList
    totalLat += mel.lat
    totalLon += mel.lon
    eventCount += 1
Next
ViewData("centerLat") = totalLat / eventCount
ViewData("centerLon") = totalLon / eventCount
现在我一直在尝试计算最佳缩放级别

编辑2: 因此,我从控制器中删除了计算,并将其添加到Javascript中。脚本的重量很轻,但将由客户端计算机而不是我的服务器完成计算(如果/当站点开始获得成堆的点击量时很有价值)

$(文档).ready(函数(){
//加载Bing地图并填充它
var increment=0;//用于增加事件位置
var sumLat=0;//用于查找平均LAT位置
var sumLon=0;//用于查找平均LON位置
//加载初始映射
LoadMap();
//循环所有事件并在地图上放置一个点
//还要添加到sumLat和sumLon变量
$.each(json_对象、函数(){
增量=++增量;
sumLat=sumLat+this.lat;
sumLon=sumLon+this.lon;
加载点(this.lat、this.lon、this.title、this.desc、increment);
});
//找到地图中心的平均纬度和经度
var centerLat=sumLat/增量;
var centerLon=sumLon/增量;
LatLon=新VELatLong(centerLat,centerLon);
//基于所有点的平均值设置新地图中心。
地图设置中心(拉特隆)
});
函数LoadMap(){
map=新的VEMap(“bingMap”);
mapOptions=新的VEMapOptions
//设置哮喘患者的地图选项
mapOptions.DashboardColor=“黑色”;
mapOptions.EnableDashboardLabels=false;
mapOptions.EnableBirdseye=false;
mapOptions.EnableDashboardLabels=false;
//加载初始映射
//注意:此时LatLon为“null”,因为我们将
//稍后根据所有点的平均值将地图居中。
LoadMap(null,zoomLevel,null,null,null,false,null,mapOptions);
};
功能加载点(纬度、经度、标题、描述、pinId){
var点=新高度(纬度、经度);
var pin=新的VEShape(VEShapeType.Pushpin,点);
pin.SetTitle(标题);
引脚设置说明(desc+“

lat:+lat+”lon:+lon); pin.SetCustomIcon(“+pinId+”); 地图。AddShape(pin); };

然而,我仍然被困在试图计算最佳缩放级别的过程中,当我遇到类似的问题时,我通过计算销的(粗略的)重心来解决它。我说“粗糙”是因为我只是平均了每个点的纬度/经度,这是不正确的,因为地球是一个球体。

当我遇到类似的问题时,我通过计算销的(粗糙)重心来解决它。我之所以说“粗略”,是因为我只是平均了每个点的纬度/经度,这是不正确的,因为地球是一个球体。

如果您使用的是javascript版本,那么您不需要计算它,您可以直接将VELatLong对象数组提供给,它将居中+缩放,使所有管脚都可见。

如果您使用的是javascript版本,则无需计算,您可以直接将VELatLong对象数组提供给,它将居中+缩放,使所有管脚都可见。

非常感谢您的回答。我在这里发布了我的结果,以帮助其他需要朝正确方向推动的人

$(document).ready(function () {
    // Load the Bing Map and populate it
    var increment = 0; // used to increment event locations
    var sumLat = 0; // used to find the average LAT location
    var sumLon = 0; // used to find the average LON location
    var latlonArray = new Array();  // used to create an Array of lat and lon in order to "SetMapView"

    // Load the initial map
    LoadMap();

    // loop through all events and place a point on the map
    // also add to the sumLat and sumLon variable
    $.each(json_object, function () {
        latlonArray[increment] = new VELatLong(this.lat, this.lon); // Add to the array before the increment
        increment = ++increment;
        sumLat = sumLat + this.lat;
        sumLon = sumLon + this.lon;
        LoadPoint(this.lat, this.lon, this.title, this.desc, increment);
    });

    // find the averate Lat and Lon for map centering
    var latlonCenter = new VELatLong(sumLat / increment, sumLon / increment);

    // Set the new map Center based on the average of all points.
    map.SetCenter(latlonCenter);
    map.SetMapView(latlonArray); // pass the latlonArray object to the SetMapView in order to display all map pins appropriately.

});
非常感谢你的回答。我在这里发布了我的结果,以帮助其他需要朝正确方向推动的人

$(document).ready(function () {
    // Load the Bing Map and populate it
    var increment = 0; // used to increment event locations
    var sumLat = 0; // used to find the average LAT location
    var sumLon = 0; // used to find the average LON location
    var latlonArray = new Array();  // used to create an Array of lat and lon in order to "SetMapView"

    // Load the initial map
    LoadMap();

    // loop through all events and place a point on the map
    // also add to the sumLat and sumLon variable
    $.each(json_object, function () {
        latlonArray[increment] = new VELatLong(this.lat, this.lon); // Add to the array before the increment
        increment = ++increment;
        sumLat = sumLat + this.lat;
        sumLon = sumLon + this.lon;
        LoadPoint(this.lat, this.lon, this.title, this.desc, increment);
    });

    // find the averate Lat and Lon for map centering
    var latlonCenter = new VELatLong(sumLat / increment, sumLon / increment);

    // Set the new map Center based on the average of all points.
    map.SetCenter(latlonCenter);
    map.SetMapView(latlonArray); // pass the latlonArray object to the SetMapView in order to display all map pins appropriately.

});

真正地里面没有什么东西吗?那么缩放级别呢?对于缩放级别,不确定是否真的构建了某些内容?里面没有什么东西吗?那么缩放级别呢?对于缩放级别,我们不确定是否有内置的东西。是的,我在看这里,我似乎不知道如何创建VELatLong.nm数组,我知道了。我会把我的答案贴在下面,但给你所有的信任。我不能再给悬赏10分钟了。。。你会明白的;-)是的,我在看这里,我似乎不知道如何创建VELatLong.nm数组,我知道了。我会把我的答案贴在下面,但给你所有的信任。我不能再给悬赏10分钟了。。。你会明白的;-)