2011-06-27 72 views

回答

2

有一种方法称为LocationRect,可用于此。以下是来自MSDN的示例:

function init(){ 
// Load the map 
var map = new Microsoft.Maps.Map(
    document.getElementById("myMap"), 
    { 
     credentials: "YOUR-BING-KEY", 
     mapTypeId: Microsoft.Maps.MapTypeId.road 
    } 
); 

// Some sample pins 
var locs = []; 
var loc1 = new Microsoft.Maps.Location(-10, 0); 
var pin1 = new Microsoft.Maps.Pushpin(loc1 , {text: '1'}); 

var loc2 = new Microsoft.Maps.Location(0, 10); 
var pin2 = new Microsoft.Maps.Pushpin(loc2, {text: '2'}); 

var loc3 = new Microsoft.Maps.Location(10, 0); 
var pin3 = new Microsoft.Maps.Pushpin(loc3, {text: '3'}); 

var loc4 = new Microsoft.Maps.Location(20, -20); 
var pin4 = new Microsoft.Maps.Pushpin(loc4, {text: '4'}); 

locs.push(loc1); 
locs.push(loc2); 
locs.push(loc3); 
locs.push(loc4); 

map.entities.push(pin1); 
map.entities.push(pin2); 
map.entities.push(pin3); 
map.entities.push(pin4); 
var bestview = Microsoft.Maps.LocationRect.fromLocations(locs); 
map.setView({bounds:bestview }); 

}