为jQuery表循环生成的标记设置边界?

为jQuery表循环生成的标记设置边界?,jquery,loops,google-maps-api-3,Jquery,Loops,Google Maps Api 3,我有一些jQuery代码,它遍历一个位置结果表,并在地图上放置相应的pin。我很难确定如何设置边界,这样当它通过循环并在地图上生成标记时,它会缩放和平移以适应视图中的标记。我尝试在这个网站上实现一些类似问题的代码,但似乎没有任何效果。请让我知道我应该使用什么代码,以及我应该把它放在脚本中的什么地方: $(function() { var latlng = new google.maps.LatLng(44, 44); var settings = { zoom: 15,

我有一些jQuery代码,它遍历一个位置结果表,并在地图上放置相应的pin。我很难确定如何设置边界,这样当它通过循环并在地图上生成标记时,它会缩放和平移以适应视图中的标记。我尝试在这个网站上实现一些类似问题的代码,但似乎没有任何效果。请让我知道我应该使用什么代码,以及我应该把它放在脚本中的什么地方:

$(function() {
   var latlng = new google.maps.LatLng(44, 44);

   var settings = {
      zoom: 15,
      center: latlng,
      disableDefaultUI: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
   };

   var map = new google.maps.Map(document.getElementById("map_canvas"), settings);

      $('tr').each(function(i) {

         var the_marker = new google.maps.Marker({
            title: $(this).find('.views-field-title').text(),
            map: map,
            clickable: true,
            position: new google.maps.LatLng(
               parseFloat($(this).find('.views-field-latitude').text()),
               parseFloat($(this).find('.views-field-longitude').text())
            )
         });

         var infowindow = new google.maps.InfoWindow({
            content:  $(this).find('.views-field-title').text() +
                      $(this).find('.adr').text()
         });

         new google.maps.event.addListener(the_marker, 'click', function() {
            infowindow.open(map, the_marker);

         });
      });
});

`在
var-map=…
下添加
var-bounds=new google.maps.bounds(latlng,latlng)

然后在
var下的循环中,添加
bounds.extend(the_marker.getPosition())

然后是结束的循环add
map.fitBounds(bounds)