Your code always calls fitBounds with LatLngBounds with only one point, the last marker ... If you call this function several times, each time you call it, Bounds of the last marker will be used. You can define the markerBounds variable outside the geocoder.geocode function, so it will keep its value.
var markerBounds = new google.maps.LatLngBounds(); geocoder.geocode( {'address': loc}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var coordinate = results[0].geometry.location; var icon = new google.maps.MarkerImage("images/icon-"+type+".png", new google.maps.Size(37, 44));
The Bounds token is now initialized once and expanded with each new token.
source share