Skip to content

Latest commit

 

History

History
42 lines (35 loc) · 607 Bytes

responsive.md

File metadata and controls

42 lines (35 loc) · 607 Bytes

Responsive google maps

Map centers on window resize

var center;

google.maps.event.addDomListener(
  map,
  'idle',
  function() {
    center = map.getCenter();
  }
);

google.maps.event.addDomListener(
  window,
  'resize',
  function() {
    map.setCenter(center);
  }
);

You can also adjust the zoom based on the browser width;

function getZoomLevel()
{
    return Math.round(Math.log($(window).width() / 512)) + 1;
}

google.maps.event.addDomListener(
  window,
  'resize',
  function() {
    var zoomLevel = getZoomLevel();
    map.setZoom(zoomLevel);
  }
);