Google Maps API - More Google Maps API Functions

Started by ganeshbala, Apr 18, 2008, 10:09 PM

Previous topic - Next topic


Map Types

Google Maps provides three types of map: a simple map that provides an outline-based map, a satellite map that streams the satellite-imaged maps and a hybrid map which combines both of the aforementioned maps. The map types provided by Google Maps are controlled by the following methods:

    *  setMapType(type) sets the type of map to be displayed.
    *  removeMapType(type) removes a map type that has already been set.

The type parameter is specified using the constants provided by the GMapType class. It can be G_NORMAL_MAP, G_SATELLITE_MAP, or G_HYBRID_MAP corresponding to maps of the simple, satellite image-based or hybrid types.

Map State

The methods that provide information about the state of the map come under this heading. The information provided by map state methods include whether the map is loaded or not, the current focus point or center of the map, and more. The commonly used methods are:

    * isLoaded() tells whether or not the map is loaded onto the client browser.
    * getCenter() provides the latitude and longitude of the center of the current view port of the map.


By definition "A map overlay refers to a point or polyline that is added on top of the Google Map." In essence an overlay means a point or line that is placed on the map to distinguish it from the rest of the map. The most used methods in this category are:

    *  addOverlay(overlay) adds an overlay presented by the overlay object passed as a parameter.
    *  removeOverlay(overlay) removes an overlay already added and represented by the overlay object passed as a parameter.

The overlay object can be of the GPoint or GPolyline types.

Information Window

When an overlay is clicked, a window containing detailed information can be displayed. It is called the information window or info window in short. The following are the main methods used to control an info window:

    * openInfoWindow(latlng,dom,[opts]) opens an information window at the point specified by latlang and with the data specified as dom which is a DOM node.
    * showMapBlowup(latlng,[opts]) opens an info window at the specified latlng containing the close-up view of the latlng specified as a parameter.

The parameter latlng is of the GLatLng type.

Map Navigation

The navigation of the map can be controlled using the methods provided under this category. The commonly used methods are:

    * setCenter(center,[zoom],[type]) loads the map focused on the point specified by center with an optional level of zoom and type of map.
    * panTo(center) navigates to the point on the map specified by center.
    * setZoom(level) zooms into or magnifies the current center to the level specified with the parameter level.


The Google Maps API provides methods to intercept any event taking placing on the map. The common events supported by the Google Maps API are:

    * click is generated when the user clicks on any point within the boundaries of the map.
    * move is fired when the map is moving or panning. During panning it may be fired many times.
    * moveend is fired when the panning is completed.

That brings us to the end of the first part of our discussion. In the next section I will detail the steps required to work with the Google Maps API.