Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

40 Part I — Basics


JavaScript


The Google Maps API is based on the JavaScript language. JavaScript (soon to be referred to
as ECMAScript as an official standard) is built into most browsers and provides a rich suite of
functionality for developing dynamic elements.

Teaching you how to program in JavaScript is beyond the scope of this book. However, Google
Maps does rely on JavaScript, so numerous examples of JavaScript applications are included
throughout this book. JavaScript is easy to use and learn, and any programmer that is already
familiar with the basic mechanics of programming should be able to adapt her skills to
JavaScript.

The majority of JavaScript programming is designed to interface directly into the Google Maps
API, which itself is based on an object-oriented interface to a suite of Google Maps–specific
classes.

Understanding API Terminology


The Google Maps API is essentially a suite of JavaScript classes that you use to build applica-
tions within the confines of a web page. Understanding the API relies on knowing the termi-
nology used to define sections of the Google Maps API and interface. Once you understand
the terminology, a closer look at the Google Maps API classes will provide the detail required
to build Google Maps applications.

All Google Maps applications start off with a simple map. To this map, you can add a number
of different elements designed to provide the application functionality. All maps support four
main elements:

Overlays:Points of interest on the map or lines denoting areas, routes, or other informa-
tion about the location being displayed.

Events:Occurrences of an operation, such as the user clicking on a point of interest.
Information:Extended data about the map, a map marker, or map region that is dis-
played as part of the map application.
Controls:Basic interface controls that enable the user to zoom in and out of the map
and move about the map effectively.

A fifth element doesn’t have a unique role in the API, but it does support the operations: The
ability to load data dynamically is key to providing the interactive elements of a typical Google
Maps application. Generally, the information is extracted from an XML file that is loaded from
the web server, either as a static file or — for true dynamism — through a dynamic component
on the web server, such as CGI script, PHP script, or Java application.
Free download pdf