<!DOCTYPE html>
<html>
<head>
<style>
#map-canvas {
width: 500px;
height: 400px;
}
</style>
//Load the Google Maps API
//this script download the codes required to dispaly map on your page
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script>
//this piece of code create the map and runs when the page is loaded
function initialize() {
var mapCanvas = document.getElementById('map-canvas');
var mapOptions = {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
//the map object constructor takes two arguments
// a reference to the div that the map will be loaded into
//options for the map,such as center,zoom and the map type
//center is a google map LatLng object that tells the api where to center the map
//zoom is a number between 0 to 22
//mapTypeId is used to specify what type of map to use
var map = new google.maps.Map(mapCanvas, mapOptions)
}
//add an eventlistener to the window object that will call the initalize function once the page has been loaded
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
No comments:
Post a Comment