I have a problem with a map on which I've used the fitBounds
map methods, which should give the proper zoom and center the map giving it a latlon array. here's the code:
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false">
</script>
<div id="map_canvas">
<script type="text/javascript">
var map;
var bounds = new google.maps.LatLngBounds(null);
function initialize() {
var mapOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
<?php
foreach ($this->getProductCollection() as $_e):
$event = Mage::getModel('catalog/product')->load($_e->getId());
?>
var loc = new google.maps.LatLng("<?php echo $event->getEventLocationLatitude(); ?>","<?php echo $event->getEventLocationLongitude(); ?>");
bounds.extend(loc);
addMarker(loc, '<?php echo $event->getName(); ?>', "active");
bounds.extend(loc);
<?php endforeach; ?>
map.fitBounds(bounds);
map.panToBounds(bounds);
}
function addMarker(location, name, active) {
var marker = new google.maps.Marker({
position: location,
map: map,
title: name,
status: active
});
}
jQuery.noConflict();
jQuery(document).ready(function(){
initialize();
});
</script>
The markers are correctly placed on the map, but I get the maximum zoom available:
Any help?
I've updated your fiddle here: http://jsfiddle.net/KwayW/1/
It works now as expected.
Here's the full code (save this as test.html and open in browser):