Google Maps JavaScript API

There is extensive documentation for the Google Maps JavaScript API, at
https://developers.google.com/maps/documentation/javascript/tutorial that you can consult. But for now, it will be enough to walk through some examples.

We'll learn by example with a

Basic Map

So first, we'll start with a map that is centered on the John Harvard statue in Harvard Yard.

To use the Google Maps JavaScript API, we'll need to load the Google Map JavaScript via a script element, and then we'll need to configure the map and then place it on the page.

Load the JavaScript:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"> </script>

Use the JavaScript:

var map;
/* John Harvard Statue
   42.374474,-71.117207 */
var mylat = 42.374474;
var mylng = -71.117207;
function initialize_map() {
    var mapOptions = {
        zoom: 17,
        center: new google.maps.LatLng(mylat, mylng)
    };
    map = new google.maps.Map(document.getElementById('map-canvas'),
    mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize_map);

Full example:

Basic Map working examples:

Copyright © David Heitmeyer