Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

42 Part I — Basics


Controls


The Google Maps API provides a number of standard controls for allowing the user to interact
at a basic level with the map. These controls are normally displayed in the top left-hand and
top right-hand corners of the map display and include the buttons for moving around the map,
zooming in and out, and selecting the map type (map, satellite imagery, or hybrid).

At the time of this writing, the available control types are as follows:

GLargeMapControl: A large pan/zoom control (with slider).
 GSmallMapControl: A smaller pan/zoom control (without slider).

 GSmallZoomControl: A small zoom control (no slider or panning controls).
 GMapTypeControl: Lets the visitor toggle among map types (map, satellite imagery,
and hybrid).

Generally, you choose the type of controls to add to the map according to the needs of the
application, but you can also let users select which controls appear.

The Google Maps Classes


All of the functionality of the Google Maps API is provided through a suite of classes designed
to build and define the elements of a Google Map. You start with the GMapclass and, through
the additional classes, define map markers and information windows, and create controls and
events that allow the user to interact with the application.

GMap


The main GMapclass creates a new Google Map within an HTML container (typically a div
element within the HTML). The format for creating a new object using the class is as follows:
GMap(container, mapTypes?, width?, height?)

Optional arguments to a function are denoted by a question mark after the argument.

The optional mapTypesargument enables you to specify which map types are available in the
application. The default is the three current solutions:G_MAP_TYPE,G_HYBRID_TYPE, and
G_SATELLITE_TYPE.

The default size of the map is the same as the container in which the map is created.
Alternatively, you can specify the width and/or height (in pixels) when creating the map.

Once the map is created, you can set a number of options, as outlined in Table 3-1. Each of the
items in this table is a method to the map object created by GMap.
Free download pdf