Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 7 — Extending the Google API Examples 105


<script src=”http://maps.google.com/maps?file=api&v=1&key=XXX
type=”text/javascript”>



This section loads the Google Maps API. You must specify the Google Maps API key and the
version of the API that you are using in this line to load the correct interface.


Once the Google Maps API is loaded, you can then call the API functions that introduce the
map components into your web page. As shown in this example, you do this by creating a new
local function,onLoad(), which is called when the page is loaded. The onLoad()function
does three things:


Checks that the browser is compatible and capable of running the Google Maps API.
Creates a new map object. Within your XHTML, you’ve defined a <div>element with
an idof ‘map’and given it a size. When you create the new map object, you specify
this element, which is where the map will appear within your site.

 Centers the map on a new GPoint. In this case, it points to my favorite local restaurant,
One on Wharf.

You now have a simple map on a web page (see Figure 7-1). You can extend this to add some
other functionality to the page.


FIGURE7-1: A simple Google Maps example.

Free download pdf