Skip to content

Instantly share code, notes, and snippets.

@thotbox
Last active August 29, 2015 14:03
Show Gist options
  • Save thotbox/ed7dc982cdb45507dafb to your computer and use it in GitHub Desktop.
Save thotbox/ed7dc982cdb45507dafb to your computer and use it in GitHub Desktop.
JavaScript: Google Map Fixes
// IE8 Map Fix - Add data-lat and data-long attributes to .map-container
if ($('html').hasClass('lt-ie9')) {
if($('.map-container').length ) {
var mapLat = $('.map-container').attr('data-lat');
var mapLong = $('.map-container').attr('data-long');
setTimeout(function() {
google.maps.event.trigger(map, 'resize');
map_map.setCenter(new google.maps.LatLng(mapLat,mapLong));
}, 500);
}
}
// Center Map on Resize - Add data-lat and data-long attributes to .map-container
$(window).resize(function() {
if($('.map-container').length ) {
var mapLat = $('.map-container').attr('data-lat');
var mapLong = $('.map-container').attr('data-long');
setTimeout(function() {
google.maps.event.trigger(map, 'resize');
map_map.setCenter(new google.maps.LatLng(mapLat,mapLong));
}, 500);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment