I am basically trying to some how set an auto-zoom and auto-center function for my #map_div
div. But because my markers are dynamically generated, I somehow need the zoom and center to work automatically, based on the width and height of my #map_div
But as you can see in my gmap3 script that I am having to determin the zoom and center manually, not cool.
I found this script snippet below, but cant see how to intergrate it with my .gmap3
script. Is it possible to integrate it somehow with my .gmap3
jquery plugin script?
Center point calculation var...
// map: an instance of google.maps.Map object
// latlng: an array of google.maps.LatLng objects
var latlngbounds = new google.maps.LatLngBounds( );
for ( var i = 0; i < latlng.length; i++ ) {
latlngbounds.extend( latlng[ i ] );
}
map.fitBounds( latlngbounds );
My .gmap3
script below...
jQuery(function($) {
$('#map_div').gmap3({
action: 'init',
options: {
center: [50.799019, -1.132037],
zoom: 5,
scrollwheel: false
}
}, {
action: 'addMarkers',
markers: [{
lat: 50.799019,
lng: -1.132037,
data: 'Test One'},
{
lat: 50.365162,
lng: -4.712017,
data: 'Test Two'},
{
lat: 54.518726,
lng: -5.881054,
data: 'Test Three'},
{
lat: 52.780964,
lng: -1.211863,
data: 'Test Four'},
{
lat: 51.433998,
lng: -2.549690,
data: 'Test Five'
}],
marker: {
options: {
draggable: false
}
}
});
});
I would normally do a jsfiddle but the site is down.
Any help with this would be so great thanks.