Setting zoom level so all pins are visible RRS feed

  • Question

  • I have a map with a bunch of unmovable pins and I would like to set the zoom at page load so that all the pins are visible on the map at the same time.  I figured I need to determine the center of the map by averaging both the latitude and longitude, and that seems to work.

    Is it possible to determine the appropriate zoom level, given the min/max coordinates for all the pins, so that all the pins are visible?  I realize that the dimensions of the map may come into play here.


    Tuesday, September 25, 2012 10:06 PM


  • Create an array of coordinates from your pushpin information and pass it into the LocationRect class then pass this in to set the view like this:

    var coords = [....];

    var bounds = Microsoft.Maps.LocationRect.fromLocations(coords);

    map.setView({bounds : bounds});


    Wednesday, September 26, 2012 8:41 AM