104 Part II — Instant Gratification
Listing 7-1:Basic Map Example
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8”/>
<title>Mcslp Maps Chapter 7, Ex 1</title>
<script src=”http://maps.google.com/maps?file=api&v=1&key=XXX”
type=”text/javascript”>
</script>
<script type=”text/javascript”>
//<![CDATA[
function onLoad() {
if (GBrowserIsCompatible()) {
var map = new GMap(document.getElementById(“map”));
map.centerAndZoom(new GPoint(-122.1419, 37.4419), 4);
}
}
//]]>
</script>
</head>
<body onload=”onLoad()”>
<div id=”map” style=”width: 800px; height: 600px”></div>
</body>
</html>
The code is split into a number of different parts and it is important to note, even at this
stage, that the majority of the information here is HTML; the actual portion of the code that
relates to the Google Maps API is comparatively small. This is generally true of most Google
Maps–based applications: A lot of the interesting code is actually in the background or simply
never seen at all.
Google advises that you use either XHTML (as in this example) or DHTML to ensure compatibil-
ity and portability.
The key component of the example is the installation of the Google Maps API JavaScript in
this portion: