Set bounds for markers generated by jQuery table loop? -
i have jquery code goes through table of location results , puts corresponding pins on map. having trouble figuring out how set bounds when goes through loop , generates markers on map zooms , pans fit markers in view. i've tried implementing code similar questions on site nothing seems working. please let me know code should using , heck should put in script:
$(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); }); }); });
`
under var map = ...
add var bounds = new google.maps.bounds(latlng, latlng);
then in loop under var the_marker = ...
add bounds.extend(the_marker.getposition());
then loop ended add map.fitbounds(bounds);
Comments
Post a Comment