Skip to content

Instantly share code, notes, and snippets.

@MrKistic
Created July 2, 2013 02:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrKistic/5906310 to your computer and use it in GitHub Desktop.
Save MrKistic/5906310 to your computer and use it in GitHub Desktop.
Example of a responsive embedded Google map. It will recenter on window resize.
<!DOCTYPE html>
<html>
<head>
<title>Google Maps JavaScript API v3 Example: Map Simple</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
<meta charset="utf-8"/>
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
}
#map_canvas {
height: 75%;
width: 75%;
margin: 0 auto;
top: 10%;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var map;
function initialize() {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(-37.8212615, 144.9508076),
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
window.onresize = function () {
lastCenter = map.getCenter();
google.maps.event.trigger(map_canvas, 'resize');
map.setCenter(lastCenter);
};
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>
@Sohaibse
Copy link

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment