Created
July 2, 2013 02:09
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice