Here is a code snippet to make Google maps API v3 to fit the view to all your markers. There is a lot of similar functions on the Internet, but they're all for the old API v2 which is sensibly different.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//set up the map
function initMap()
{
  var myOptions = {
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById("mapCanvas"), myOptions);
}
 
//set up your markers
function initMarkers()
{
  //...
}
 
var map;
var bound = new google.maps.LatLngBounds();
var markers = new Array();
 
//jQuery style entry point, change if necessary
$(document).ready(function(){
  initMap();
  initMarkers();
 
  for(var i in markers)
  {
    bound.extend(markers[i].getPosition());
  }
  map.fitBounds(bound);
});